admin 管理员组文章数量: 1086019
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
1 Answer
Reset to default 11Wow, 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
本文标签: newlineIs there an alternate spelling of n in javascriptStack Overflow
版权声明:本文标题:newline - Is there an alternate spelling of n in javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744059912a2526533.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论