Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Carriage Return, Line Feed and New Line

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?

like image 922
arvind.mohan Avatar asked Sep 12 '12 11:09

arvind.mohan


People also ask

What is the difference between a carriage return and line feed?

Carriage return is from the days of the teletype printers/old typewriters, where literally the carriage would return to the next line, and push the paper up. This is what we now call \r . Line feed LF signals the end of the line, it signals that the line has ended - but doesn't move the cursor to the next line.

Is a carriage return a new line?

In Windows, a new line is denoted using “\r\n”, sometimes called a Carriage Return and Line Feed, or CRLF.

What is form feed and carriage return?

Form feed is a page-breaking ASCII control character. It forces the printer to eject the current page and to continue printing at the top of another. Often, it will also cause a carriage return. The form feed character code is defined as 12 (0xC in hexadecimal), and may be represented as control+L or ^L .

Is carriage return the same as enter?

Many webpages said that ASCII code for enter key is 13(0d). Enter key is considered as Carriage Return (CR).


1 Answers

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

like image 172
jonvuri Avatar answered Sep 24 '22 01:09

jonvuri