开发者

CR followed by 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 th开发者_运维问答ere 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?


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜