Escape new lines with JS

后端 未结 3 1612
情歌与酒
情歌与酒 2021-02-13 23:49

I have a string that looks something like this:

\"Line 1\\nLine 2\"

When I call length on it, though, it\'s one character short:



        
3条回答
  •  太阳男子
    2021-02-14 00:19

    \n is the newline character. You can use "Line 1\\nLine 2" to escape it.

    Keep in mind that the actual representation of a new line depends on the system and could be one or two characters long: \r\n, \n, or \r

提交回复
热议问题