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

     
  • 相关阅读:
    高斯模糊原理,算法
    SIFT算法详解
    第五章:状态图
    ANTLR4权威指南
    第八章:包图,组件图,部署图
    棋盘n皇后问题-递归
    普通页面引入React(使用和不使用JSX)
    浏览器环境
    DevTool-Network
    优化浏览器渲染
  • 原文地址:https://www.cnblogs.com/chucklu/p/15309998.html
Copyright © 2011-2022 走看看