Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between this characters? [duplicate]

Possible Duplicate:
What is the difference between \r and \n?

I really would like to know what's the difference between \n , \r , \t , chr(13) , how they are used in a web application, in which OS, and so on.

For example, can you confirm that windows uses \n\r for the newline, while of linux uses just \n right? It would be interesting to know these things.

Thanks

like image 646
kwichz Avatar asked Dec 10 '22 08:12

kwichz


1 Answers

These are character escape sequences in many languages (c, c++, java, javascript, .NET to name a few). They directly translate to the equivalent ASCII values (you posted this as chr(13) which in one language would produce a character based on that ASCII value).

Their meanings are:

\n == chr(13) == carriage return
\r == chr(10) == line feed
\t == chr (9) == tab

These all come from control characters for printers, in turn coming from typewriters.

A carriage return brings the typewriter to the beginning of the line.

A line feed brings the typewriter to the next line.

A tab moves the typewriter to the next tab stop.

A combination of line feed and carriage return is needed to bring the typewriter to the start of the next line.

The differences between windows and unix stem from the different decisions on the different platforms on how to represent a new line. Unix went with carriage return (probably also to save space), Windows with both. Macs used to use linefeeds for the same.

like image 64
Oded Avatar answered Dec 26 '22 20:12

Oded