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

What is the difference between this two strings?

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

\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.

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

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

Its the newline representation for different operating systems. In windows a new line is \r\n and Linux its \n.


The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .
Read More:   Correct way Provide DomSanitizer to Component with Angular 2 RC6

Similar Posts