Javascript 什么是 \r",为什么要与 \n 一起使用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10282314/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is a \r" and why would one use it with a \n?
提问by Danny Fox
What is the difference between this two strings?
这两个字符串有什么区别?
"first line \n second line"
, "first line \r\n second line"
"first line \n second line"
, "first line \r\n second line"
回答by adarshr
\r
- Carriage Return\n
- Line Feed
\r
- 回车 - 换\n
行
\r\n
is often used in preference to \n
as it displays properly on both unix and Windows.
\r\n
通常优先使用 ,\n
因为它可以在 unix 和 Windows 上正确显示。
Carriage Return just returns the cursor to the beginning of the same line (without advancing to the next line) whereas a Line Feed feeds a new line.
回车只是将光标返回到同一行的开头(不前进到下一行),而换行则换行。
Note:(hover over the grey box below to find out)
注意:(将鼠标悬停在下面的灰色框上以查找)
If you ever get hold of a typewriter, try using it. It is such a magnificent piece of engineering which not many get to experience these days.
如果您曾经拥有打字机,请尝试使用它。这是一项如此宏伟的工程,如今很少有人能够体验到。
回答by Fabrizio Calderan
the difference is in the different EOL
system (Unix like first, Win/DOS second)
区别在于不同的EOL
系统(首先像 Unix,其次是 Win/DOS)
回答by eabraham
Its the newline representation for different operating systems. In windows a new line is \r\n and Linux its \n.
它是不同操作系统的换行符。在 Windows 中,新行是 \r\n,而 Linux 是 \n。