JavaScript Platform Independent Line separator

前端 未结 6 1174
一整个雨季
一整个雨季 2020-12-09 09:03

Does something similar to Java\'s System.getProperty(\"line.separator\"); exist in JavaScript?

Edit: I am using the non-browser JavaScript environment

6条回答
  •  旧时难觅i
    2020-12-09 09:33

    This is best answered on ... wait for it ... StackOverflow! Where the question includes one function to determine line break character, and the answer linked here provides a way to detect platform, and then deduce platform sensitive line break character for use within pre or textarea.

    In the browser, how does one determine which flavour of line breaks is appropriate to the OS?

    Also, you can find a good explanation of how outside a pre and textarea, JavaScipt converts all line separators to \n here: http://www.bennadel.com/blog/161-Ask-Ben-Javascript-Replace-And-Multiple-Lines-Line-Breaks.htm

提交回复
热议问题