I have an application in which I receive a comment string from REST Api like this
"comments":"This is a comment\nAnother comment\nOne more\nLast
I'm displaying it using p tag but it's not recognizing line breaks(\n). How to have a newline?
To add a line break to your HTML code, you use the <br> tag. The <br> tag does not have an end tag. You can also add additional lines between paragraphs by using the <br> tags.
Operating systems have special characters denoting the start of a new line. For example, in Linux a new line is denoted by “\n”, also called a Line Feed. In Windows, a new line is denoted using “\r\n”, sometimes called a Carriage Return and Line Feed, or CRLF.
The \n character matches newline characters.
The line end (EOL), line break, line feed, line break or carriage return character is a control character, which is the end of a text line, and the following character should start in a different line. It's \r\n on the Windows system, and it's Linux on \n.
<pre>
tag is set to recognize newlines. You can make the <p>
behave like <pre>
via CSS but you will loose any HTML in the <p>
(if there are any).
Alternatively, you have to replace them with HTML linebreak <br>
or <br/>
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