Question

What are the differences among Carriage Return, Line Feed and New line? Does it depend on OS? Why do we need to use all of them just for getting to next line?

Was it helpful?

Solution

Generally, a "new line" refers to any set of characters that is commonly interpreted as signaling a new line, which can include:

  • CR LF on DOS/Windows
  • CR on older Macs
  • LF on Unix variants, including modern Macs

CR is the Carriage Return ASCII character (Code 0x0D), usually represented as \r. LF is the Line Feed character (Code 0x0A), usually represented as \n.

Original typewriter-based computers needed both of these characters, which do exactly what they say: CR returned the carriage to the left side of the paper, LF fed it through by one line. Windows kept this sequence unmodified, while Unix variants opted for more efficient character usage once they were only needed symbolically.

Make sure you look for a platform-agnostic new line symbol or function if you need to represent this sequence in code. If not, at least make sure that you account for the above three variants.

More on the history: http://www.codinghorror.com/blog/2010/01/the-great-newline-schism.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top