JavaScript string with new line - but not using \n

前端 未结 8 2066
故里飘歌
故里飘歌 2020-11-27 05:44

I have a string that has new lines in. I am wanting to convert these to HTML
s, but I\'m having a hard time detecting them.

Imagine a JavaScri

8条回答
  •  一整个雨季
    2020-11-27 05:52

    I don't think you understand how \n works. The resulting string still just contains a byte with value 10. This is represented in javascript source code with \n.

    The code snippet you posted doesn't actually work, but if it did, the newline would be equivalent to \n, unless it's a windows-style newline, in which case it would be \r\n. (but even that the replace would still work).

提交回复
热议问题