I'm trying to convert newlines to breaks. But for some reason I can't get this to work. I did various tests, and I know the function is being executed, and that the variable passed to the function is definitely a string. It's weird that this does not work. Since I use exactly the same function for double escaping newlines before I send it to the server. I have tried a lot of things, and do not understand why this does not work.
console.log(ev);
var parsedJSON = JSON.parse(ev.data);
console.log('string that goes in function:' + parsedJSON.message);
//typeof(parsedJSON.message); string
var bericht = placeBreaks(parsedJSON.message);
function placeBreaks(str) {
return str.replace(/\r?\n/g, "<br />");
}
console.log('string being returned: ' + bericht);
json: { "date": 1431199838, "name": "Root", "message": "test\ntest"}
(index):167 string that goes in function:test\ntest
(index):173 placeBreaks return: test\ntest
you can use
replace \n with \r
try this in vim editor
%s/\\n/\r/gec
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