我想知道两者之间的区别(如果可能的话,请举例说明) CR LF (Windows)、LF (Unix)和CR (Macintosh)三种换行类型。


当前回答

NL源自EBCDIC NL = x'15',这将在逻辑上与CRLF x'odoa ascii进行比较…当将数据从大型机物理移动到中端时,这一点变得非常明显。口头上(只有奥术人士才会使用缩略语),NL已经等同于CR或LF或CRLF

其他回答

CR和LF为控制字符,分别编码为0x0D(十进制13)和0x0A(十进制10)。

它们用于标记文本文件中的换行符。正如您所指出的,Windows使用两个字符CR LF序列;Unix只使用LF,旧的MacOS(前osx MacIntosh)使用CR。

杜撰的历史观点:

As indicated by Peter, CR = Carriage Return and LF = Line Feed, two expressions have their roots in the old typewriters / TTY. LF moved the paper up (but kept the horizontal position identical) and CR brought back the "carriage" so that the next character typed would be at the leftmost position on the paper (but on the same line). CR+LF was doing both, i.e. preparing to type a new line. As time went by the physical semantics of the codes were not applicable, and as memory and floppy disk space were at a premium, some OS designers decided to only use one of the characters, they just didn't communicate very well with one another ;-)

大多数现代文本编辑器和面向文本的应用程序提供选项/设置等,允许自动检测文件的行尾约定并相应地显示它。

它实际上只是关于文件中存储哪些字节。CR是一个字节码,用于回车(从打字机时代开始),LF类似地用于换行。它只是引用作为行末标记的字节。

维基百科上总是有更多的信息。

NL源自EBCDIC NL = x'15',这将在逻辑上与CRLF x'odoa ascii进行比较…当将数据从大型机物理移动到中端时,这一点变得非常明显。口头上(只有奥术人士才会使用缩略语),NL已经等同于CR或LF或CRLF

杰夫·阿特伍德最近有一篇关于这个问题的博客文章:伟大的换行符分裂

以下是维基百科的精华:

The sequence CR+LF was in common use on many early computer systems that had adopted teletype machines, typically an ASR33, as a console device, because this sequence was required to position those printers at the start of a new line. On these systems, text was often routinely composed to be compatible with these printers, since the concept of device drivers hiding such hardware details from the application was not yet well developed; applications had to talk directly to the teletype machine and follow its conventions. The separation of the two functions concealed the fact that the print head could not return from the far right to the beginning of the next line in one-character time. That is why the sequence was always sent with the CR first. In fact, it was often necessary to send extra characters (extraneous CRs or NULs, which are ignored) to give the print head time to move to the left margin. Even after teletypes were replaced by computer terminals with higher baud rates, many operating systems still supported automatic sending of these fill characters, for compatibility with cheaper terminals that required multiple character times to scroll the display.

既然没有这样的答案,我就简单地总结一下:

回车(MAC pre-OSX)

CR r \ ASCII码13

换行(Linux, MAC OSX)

低频 \ n ASCII码10

回车和换行(Windows)

CRLF \ r \ n ASCII码13,ASCII码10

如果你看到奇怪格式的ASCII码,它们只是不同基数/基数的数字13和10,通常以8为基数(八进制)或以16为基数(十六进制)。

http://www.bluesock.org/~willg/dev/ascii.html