Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a \r" and why would one use it with a \n?

Tags:

What is the difference between this two strings?

"first line \n second line" , "first line \r\n second line"

like image 459
Danny Fox Avatar asked Apr 23 '12 14:04

Danny Fox


People also ask

What is the use of \r and \n?

\n is used for the newline or linefeed, whereas \r is the carriage return.

What is the difference between \r and \n?

They're different characters. \r is carriage return, and \n is line feed. On "old" printers, \r sent the print head back to the start of the line, and \n advanced the paper by one line. Both were therefore necessary to start printing on the next line.

Whats does \r do?

This is an easy one! In most computer languages “\r” represents a “carriage return”. The two characters when entered into a computer program will be replaced by a single character with the ASCII code of 13.

What does \r represent in HTML?

Definition and Usage. The \r metacharacter matches carriage return characters.


2 Answers

\r - Carriage Return
\n - Line Feed

\r\n is often used in preference to \n as it displays properly on both unix and Windows.

Carriage Return just returns the cursor to the beginning of the same line (without advancing to the next line) whereas a Line Feed feeds a new line.

Note: (hover over the grey box below to find out)

If you ever get hold of a typewriter, try using it. It is such a magnificent piece of engineering which not many get to experience these days.

like image 152
adarshr Avatar answered Oct 11 '22 15:10

adarshr


the difference is in the different EOL system (Unix like first, Win/DOS second)

see http://en.wikipedia.org/wiki/Newline

like image 40
Fabrizio Calderan Avatar answered Oct 11 '22 14:10

Fabrizio Calderan