zoukankan      html  css  js  c++  java
  • 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 and 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, ) 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, ) 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, ) 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

    TortoiseDiff显示出来的区别

    001CarriageReturn.txt  换行符显示为<--

    002LineFeed.txt 换行符显示为向下的箭头

    003EndOfLine.txt  换行符显示为回车符号

    LabVIEW Termination Characters

     
  • 相关阅读:
    关于将so 打包入APK的问题
    求 在独立service 中 调用contentprovider的方法
    ndk 环境下 c版 md5
    请教大牛们一个问题
    编写 service 与导出 jar 时注意的问题
    引入已编译好的动态库
    PHP 日期格式说明
    Ocaml 插件
    【转】简单至极的 PHP 缓存类
    PHP mysqlnd cannot connect to MySQL 4.1+ using old authentication
  • 原文地址:https://www.cnblogs.com/chucklu/p/15309998.html
Copyright © 2011-2022 走看看