如何在Javascript字符串中插入<cr>(回车符)?

时间:2017-10-10 18:32:58

标签: javascript string notepad++ carriage-return

我需要在字符串中插入回车符。据我所知,\r应该这样做,但问题在于:

我在浏览器控制台中写了这个:1\r2然后我得到:12作为回报。现在我将它复制/粘贴到Notepad ++ https://imgur.com/a/pUW8p

那里有CR和LF。我如何只添加一个CR?

请注意,您可以在记事本中替换LF(\ n),保存文件并且LF已经消失。

1 个答案:

答案 0 :(得分:1)

在ES6中使用字符串模板,您只需将回车引入为书面文本。 您也可以使用\n在引用的字符串中标记回车。

const str = `l
e`;

console.log(str);

const str2 = 'l\ne';

console.log(str2);

相关问题