JavaScript string newline character?

后端 未结 15 2221
终归单人心
终归单人心 2020-11-22 08:06

Is \\n the universal newline character sequence in Javascript for all platforms? If not, how do I determine the character for the current environment?

I

15条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-22 08:29

    It might be easiest to just handle all cases of the new line character instead of checking which case then applying it. For example, if you need to replace the newline then do the following:

    htmlstring = stringContainingNewLines.replace(/(\r\n|\n|\r)/gm, "
    ");

提交回复
热议问题