Linux 这些字符有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6009038/
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's the difference between this characters?
提问by kwichz
Possible Duplicate:
What is the difference between \r and \n?
可能的重复:
\r 和\n 之间有什么区别?
I really would like to know what's the difference between \n
, \r
, \t
, chr(13)
, how they are used in a web application, in which OS, and so on.
我真的很想知道\n
, \r
, \t
,之间有什么区别,chr(13)
它们在 Web 应用程序中的使用方式,在哪个操作系统中等等。
For example, can you confirm that windows uses \n\r
for the newline, while of linux uses just \n
right? It would be interesting to know these things.
例如,你能确认windows使用\n\r
换行符,而linux使用\n
恰到好处吗?知道这些事情会很有趣。
Thanks
谢谢
采纳答案by Vijay
\n - Line Feed - 0x0A - 10 decimal - LF
\n - 换行符 - 0x0A - 十进制 10 - LF
\r - Carriage Return - 0X0D - 13 decimal - CR
\r - 回车符 - 0X0D - 十进制 13 - CR
\t - tab - 0x09 - 9 decimal - ht (horizontal tab)
\t - 制表符 - 0x09 - 9 十进制 - ht(水平制表符)
For detailed hex, decimal values refer: http://web.cs.mun.ca/~michael/c/ascii-table.html
有关详细的十六进制、十进制值,请参阅:http: //web.cs.mun.ca/~michael/c/ascii-table.html
CR+LF: DEC TOPS-10, RT-11 and most other early non-Unix and non-IBM OSes, CP/M, MP/M, DOS (MS-DOS, PC-DOS, etc.), Atari TOS, OS/2, Microsoft Windows, Symbian OS, Palm OS
CR+LF:DEC TOPS-10、RT-11 和大多数其他早期非 Unix 和非 IBM 操作系统、CP/M、MP/M、DOS(MS-DOS、PC-DOS 等)、Atari TOS、 OS/2, Microsoft Windows, Symbian OS, Palm OS
LF+CR: Acorn BBC spooled text output.
LF+CR:Acorn BBC 假脱机文本输出。
CR: Commodore 8-bit machines, Acorn BBC, TRS-80, Apple II family, Mac OS up to version 9 and OS-9
CR:Commodore 8 位机器、Acorn BBC、TRS-80、Apple II 系列、Mac OS 版本 9 和 OS-9
LF: Multics, Unix and Unix-like systems (GNU/Linux, AIX, Xenix, Mac OS X, FreeBSD, etc.), BeOS, Amiga, RISC OS, and others. However, in tty 'raw mode', CR+LF is used for output and CR is used for input.
LF:Multics、Unix 和类 Unix 系统(GNU/Linux、AIX、Xenix、Mac OS X、FreeBSD 等)、BeOS、Amiga、RISC OS 等。但是,在 tty 'raw mode' 中,CR+LF 用于输出,CR 用于输入。
RS: QNX pre-POSIX implementation.
RS:QNX pre-POSIX 实现。
For more details on \n, \r \t refer:
有关 \n 的更多详细信息,\r \t 请参阅:
http://en.wikipedia.org/wiki/Newline
http://en.wikipedia.org/wiki/Newline
http://en.wikipedia.org/wiki/Carriage_return
http://en.wikipedia.org/wiki/Carriage_return
http://en.wikipedia.org/wiki/Horizontal_tab
http://en.wikipedia.org/wiki/Horizontal_tab
To use \n \r \t in html for you can use the below codes:
要在 html 中使用 \n \r \t ,您可以使用以下代码:
\n in html == or 
 linux, Unix and Mac OS X
\r in html == or 
 Mac(classic)
\r\n in html == or 
 Windows
\t in html == 	 or 	
回答by Oded
These are character escape sequences in many languages (c, c++, java, javascript, .NET to name a few). They directly translate to the equivalent ASCII values (you posted this as chr(13)
which in one language would produce a character based on that ASCII value).
这些是许多语言(c、c++、java、javascript、.NET 等)中的字符转义序列。它们直接转换为等效的 ASCII 值(您将chr(13)
其发布为在一种语言中会根据该 ASCII 值生成字符)。
Their meanings are:
它们的含义是:
\n == chr(13) == carriage return
\r == chr(10) == line feed
\t == chr (9) == tab
These all come from control characters for printers, in turn coming from typewriters.
这些都来自打印机的控制字符,反过来又来自打字机。
A carriage return brings the typewriter to the beginning of the line.
A line feed brings the typewriter to the next line.
A tab moves the typewriter to the next tab stop.
回车将打字机带到行首。
换行将打字机带到下一行。
一个制表符将打字机移动到下一个制表位。
A combination of line feed and carriage return is needed to bring the typewriter to the start of the next line.
需要结合换行和回车才能将打字机带到下一行的开头。
The differences between windows and unix stem from the different decisions on the different platforms on how to represent a new line. Unix went with carriage return (probably also to save space), Windows with both. Macs used to use linefeeds for the same.
windows 和 unix 之间的差异源于不同平台上关于如何表示新行的不同决定。Unix 使用回车(可能也是为了节省空间),Windows 两者都使用。Mac 过去常常使用换行符。
回答by Britchie
The 13
in chr(13)
is the ASCII code for carriage return. There are numerous ASCII charts to look at for more codes to use with chr()
.
该13
中chr(13)
是回车的ASCII码。有许多 ASCII 图表可供查看以获取更多可用于chr()
.
- Windows uses a carriage return \ newline (
\r\n
) to denote a new line. - MacOS uses a carriage return only (
\r
) - Linux and Unix generally uses a new line only (
\n
).
- Windows 使用回车 \ newline (
\r\n
) 来表示新行。 - MacOS 仅使用回车 (
\r
) - Linux 和 Unix 通常只使用换行符 (
\n
)。