CR 后接 LF

发布于 2024-11-28 01:45:26 字数 192 浏览 1 评论 0原文

我读过一些关于回车(CR)和换行(LF)之间差异的文章。据我所知,生成新行时它们是相同的。但是当我像 \r\n 这样将它们放在一起时,行的更改只发生一次。当我改变像 \n\r 这样的顺序或在它们之间插入像 \rblablabla\n 这样的东西时,行的变化会发生两次。谁能告诉我为什么?这是因为我的 Windows 操作系统将 CR 后紧跟着 LF 作为单个转义字符吗?

I've read some articles about difference between Carriage Return (CR) and Line Feed (LF). To my knowledge, they are the same when generating a new line. But when I put them together like \r\n, change of line only happen once. When I alter there order like \n\r or insert something between them like \rblablabla\n, the change of line happens twice. Can anyone tell me why? Is this because my Windows OS see the CR followed immediately by a LF as a single escape character?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

帝王念 2024-12-05 01:45:26

CR 和 LF 只是字符。另一个概念开始发挥作用:换行符,计算系统中用于定义何时换行的约定开始。一些主要的选择只是 LF,就像在 Unix 中一样;只是 CR,如 MacOS(OS X 之前);和 CRLF,在 MSDOS 和后来的 Windows 中。

有用的工具通常会容忍并接受操作系统标准以外的其他形式。您可以在编程语言(例如Python)和许多文本编辑器中看到这一点。因此,您使用的工具不仅仅支持 CRLF 作为换行符。由于 LFCR 与 CRLF 不同,因此它被视为两个换行符。我认为这不是Windows层面的,而是具体应用程序层面的;例如,记事本无法以任何有用的方式显示使用 LF 的文件。

CR and LF are just characters. Another concept comes into play: newlines, the convention used in a computing system to define when a new line begins. Some of the main choices made are just a LF, as in Unix; just CR, as in MacOS (pre OS X); and CRLF, in MSDOS and, later, Windows.

Helpful tools will often be tolerant and accept other forms than the OS-standard. You see this in programming languages (e.g., Python) and many text editors. So what's happening is the tool you're using supports more than just CRLF as a newline. Since LFCR is distinct from CRLF, it is treated as two newlines. I don't think this is at the level of Windows, but specific applications; Notepad, for example, fails to show a file using LF in any sort of useful fashion.

骄兵必败 2024-12-05 01:45:26

我相信 Windows 可以识别 CR、LF 和 CRLF,但不能识别 LFCR,因此它会被解释为(由于缺乏更好的词)LF,然后是 CR,从而产生两个结束行。如果我错了,有人评论并纠正我,只是冒险猜测

Windows, I believe, recognizes CR, LF, and CRLF, but not LFCR, thus it gets interpreted (for lack of a better word) as LF, then CR, resulting in two end-lines. Somebody comment and correct me if I'm wrong, just hazarding a guess

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文