最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

newline - Is there an alternate spelling of n in javascript? - Stack Overflow

programmeradmin2浏览0评论

Due to a bug in the Tumblr theme editor, any time the sequence \n appears in the source code, it is converted to an actual line break in the source code itself. Therefore, putting the \n sequence into a Javascript string causes the program to crash, as it breaks the string into multiple lines.

I was wondering if there is another way to notate the newline character in JavaScript, which could allow me to work around this issue.

Due to a bug in the Tumblr theme editor, any time the sequence \n appears in the source code, it is converted to an actual line break in the source code itself. Therefore, putting the \n sequence into a Javascript string causes the program to crash, as it breaks the string into multiple lines.

I was wondering if there is another way to notate the newline character in JavaScript, which could allow me to work around this issue.

Share Improve this question asked Jul 26, 2018 at 14:23 14jbella14jbella 5354 silver badges15 bronze badges 1
  • 1 Sometimes with cases like this I try a double backslash like: \\n as a first workaround. I don't know if it will help or not in this case. – JonSG Commented Jul 26, 2018 at 14:43
Add a ment  | 

1 Answer 1

Reset to default 11

Wow, that's an ugly bug.

Yes, you can use \u000a instead (or \u000A). It's the Unicode escape sequence for the same character. (Or worse case: String.fromCharCode(10).)

Gratuitous example:

console.log("\n" === "\u000a");                // true
console.log("\n" === "\u000A");                // true
console.log("\n" === String.fromCharCode(10)); // true

发布评论

评论列表(0)

  1. 暂无评论