I have a string which contain new line character /n. Trying to display
the string. Instead of taking the /n as new line, it displays '/n' as text.
$scope.myOutput = " Hello /n"
{{ myOutput | textFormat }}
Required -> Hello (on html page)
Tried :
app.filter('textFormat', function() {
return function(x) {
return x.replace(/\\n/g, '<br/>');
}
Tried css styles like white-space: pre;
The newline character ( \n ) is called an escape sequence, and it forces the cursor to change its position to the beginning of the next line on the screen. This results in a new line.
\r and \n are characters denoted with ASCII values of 13 (CR) and 10 (LF), respectively. They both represent a break between two lines, but operating systems use them differently. On Windows, a sequence of two characters is used to start a new line, CR immediately followed by LF.
Press ALT+ENTER to insert the line break.
The newline character is \n in JavaScript and many other languages. All you need to do is add \n character whenever you require a line break to add a new line to a string.
This does not replace it, but you can use the CSS attribute white-space: pre-line;
to render the \n in the browser:
https://developer.mozilla.org/en-US/docs/Web/CSS/white-space
div {
white-space: pre-line;
}
<div>Foo
Bar
Baz Foo
Bar
Baz
</div>
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