开发者

javascript: replace linebreak

开发者 https://www.devze.com 2022-12-19 08:30 出处:网络
I\'m having a string which contains a chr(13) as lineb开发者_如何学JAVAreak. How can i replace it with eg. <br>? I tried mystring.replace(\"\\n\",\"<br>\"); but it didn\'t work

I'm having a string which contains a chr(13) as lineb开发者_如何学JAVAreak. How can i replace it with eg. <br>? I tried mystring.replace("\n","<br>"); but it didn't work

Thanks in advance.


"\n" is chr(10). I think you want "\r":

mystring.replace("\r", "<br>");

Updated: To replace ALL \r use a regular expression:

mystring.replace(/\r/g, "<br>");

If you want it to work with Windows, Unix and Mac style line breaks use this:

mystring.replace(/\r?\n|\r/g, "<br>");


theString.replace(/\n|\r/g, '<br />')
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号