Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between \r\n, \r, and \n? [duplicate]

Tags:

string

What is difference in a string between \r\n, \r and \n? How is a string affected by each?

I have to replace the occurrences of \r\n and \r with \n, but I cannot get how are they different in a string...

I know that \r is like hitting enter and \n is for a new line.

like image 213
Haya Raed Avatar asked Mar 15 '13 13:03

Haya Raed


People also ask

What does \r and \n mean?

\n means new line. It means that the cursor must go to the next line. \r means carriage return. It means that the cursor should go back to the beginning of the line.

Are \n and \r the same?

historically a \n was used to move the carriage down, while the \r was used to move the carriage back to the left side of the page.

What does \r and \n mean in Python?

In Python strings, the backslash "\" is a special character, also called the "escape" character. It is used in representing certain whitespace characters: "\t" is a tab, "\n" is a newline, and "\r" is a carriage return.

What is \r in a string?

Just (invisible) entries in a string. \r moves cursor to the beginning of the line. \n goes one line down.


1 Answers

  • \r = CR (Carriage Return) → Used as a new line character in Mac OS before X
  • \n = LF (Line Feed) → Used as a new line character in Unix/Mac OS X
  • \r\n = CR + LF → Used as a new line character in Windows
like image 120
Tom Bowen Avatar answered Oct 10 '22 19:10

Tom Bowen