Difference between CR LF, LF and CR line break types?

发布时间:2022-07-05 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了Difference between CR LF, LF and CR line break types?脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

Difference between CR LF, LF and CR line break tyPEs?

I'd like to know the difference (wITh examples if possible) between CR LF (Windows), LF (Unix) and CR (Macintosh) line break types.

 

评论

CR and LF are ASCII and Unicode control characters while r and n are abstractions used in certain PRogramming languages. Closing this question glosses over fundamental differences between the questions and perpetuates misinformation.

 

回答1

CR and LF are control characters, respectively coded 0x0D (13 decimal) and 0x0A (10 decimal).

They are used to mark a line break in a text file. As you indicated,

Windows uses two characters the CR LF sequence;

Unix only uses LF

and the old MacOS ( pre-OSX MacIntosh) used CR.

An apocryphal historical perspective:

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 ;-)

Most modern text editors and text-oriented applications offer options/settings etc. that allow the automatic detection of the file's end-of-line convention and to display it accordingly.

 

 

回答

This is a good summary I found:

The Carriage Return (CR) character (0x0D, r) moves the cursor to the beginning of the line without advancing to the next line. This character is used as a new line character in Commodore and Early Macintosh operating Systems (OS-9 and earlier).

The Line Feed (LF) character (0x0A, n) moves the cursor down to the next line without returning to the beginning of the line. This character is used as a new line character in UNIX based systems (Linux, Mac OSX, etc)

The End of Line (EOL) sequence (0x0D 0x0A, rn) is actually two ASCII characters, a combination of the CR and LF characters. It moves the cursor both down to the next line and to the beginning of that line. This character is used as a new line character in most other non-Unix operating systems including Microsoft Windows, Symbian OS and others.

Source

 

 

 

 

 

脚本宝典总结

以上是脚本宝典为你收集整理的Difference between CR LF, LF and CR line break types?全部内容,希望文章能够帮你解决Difference between CR LF, LF and CR line break types?所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。