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


当前回答

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

回车(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

其他回答

这是我发现的一个很好的总结:

回车符(CR)字符(0x0D, \r)将光标移动到行首,而不移动到下一行。此字符在Commodore和早期Macintosh操作系统(OS-9及更早版本)中用作新行字符。

换行(LF)字符(0x0A, \n)将光标向下移动到下一行,而不返回到行首。此字符在基于UNIX的系统(Linux、Mac OSX等)中用作新行字符。

行结束(EOL)序列(0x0D 0x0A, \r\n)实际上是两个ASCII字符,是CR和LF字符的组合。它将光标向下移动到下一行和该行的开头。该字符在大多数其他非unix操作系统(包括Microsoft Windows、Symbian OS和其他操作系统)中用作新行字符。

“记录分隔器”或“行终止器”的可悲状态是计算黑暗时代的遗产。

现在,我们理所当然地认为我们想要表示的任何东西在某种程度上都是结构化的数据,并且符合定义行、文件、协议、消息、标记等的各种抽象。

But once upon a time this wasn't exactly true. Applications built-in control characters and device-specific processing. The brain-dead systems that required both CR and LF simply had no abstraction for record separators or line terminators. The CR was necessary in order to get the teletype or video display to return to column one and the LF (today, NL, same code) was necessary to get it to advance to the next line. I guess the idea of doing something other than dumping the raw data to the device was too complex.

Unix和Mac实际上为行尾指定了一个抽象,想象一下。遗憾的是,他们指定的是不同的。(Unix,咳咳,是先出现的。)当然,他们使用的控制代码已经“接近”于S.O.P.

由于今天我们几乎所有的操作软件都是Unix、Mac或MS操作SW的后代,我们陷入了行尾的混乱。

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

以下是维基百科的精华:

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.

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

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

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