Inserts HTML Line Breaks Before All Newlines In A String
Join the DZone community and get the full member experience.Join For Free
class String def nl2br! self.gsub("\n\r","Example:
").gsub("\r", "").gsub("\n", "
") end end
text 'line_1 line_2'.nl2br!Result in HTML:
Opinions expressed by DZone contributors are their own.