javascript replace newline
function nl2br(str){
return str.replace(/(?:\r\n|\r|\n)/g, '<br>');
}
var stringWithNewLines= `Well this is a
a very broken
sentance`;
var stringWithBrs=nl2br(stringWithNewLines);
// stringWithBrs= "Well this is a<br>a very <br>broken<br>sentance"var r = "I\nam\nhere";
var s = r.replace(/\n/g,' ');let multilineString = `My
text\r1\r\n2\n3\n\r4
is
here`;
let htmlText = multilineString.replace(/(\r\n|\n\r|\r|\n)/g, '<br>');
console.log('Multiline string: ' + multilineString);
console.log('HTML text: ' + htmlText);
Also in JavaScript:
- javascript jqgrid events afterShowForm
- JavaScript and HTML DOM Reference
- how to find the current date and time of a city in js
- cypress disabled
- remove duplicates array javascript
- javascript go to top of page
- how to use static file node js
- loopback model count
- beautiful day at the movies hackerrank solution
- set attribute javascript background image
- upgrade nodejs ubuntu
- javascript array reorder elements
- vuejs pass data to router-view
- jquery google cdn
- remove special characters from string javascript
- how to create a package.json file in npm
- jquery use variable in string
- js set visibility on timeout
- parseint array javascript
- javascript variable shortcuts
- js detect all images errors
- Converting from HttpClient to Native HTTP
- jasmine spy return value when using create Spy Object angular 2
- javascript array remove first