I'm parsing text from file with Python. I have to replace all newlines (\n) with
cause this text will build html-content. For example, here is some line from file:
'title\n'
Now I do:
thatLine.replace('\n', '<br />') print thatLine
And I still see the text with newline after it.
The RegEx is used with the replace() method to replace all the line breaks in string with <br>. The pattern /(\r\n|\r|\n)/ checks for line breaks. The pattern /g checks across all the string occurrences.
Replace new line (\n) with HTML br tag in string using Java uses the \n character, also known as Line Feed (LF) character, to move the cursor to the next line. Windows uses \r\n characters to specify the start of the line, sometimes also called Carriage Return and Line Feed (CRLF).
thatLine = thatLine.replace('\n', '<br />')
str.replace() returns a copy of the string, it doesn't modify the string you pass in.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With