The difference between \r,\n,\r\n

Source: Internet
Author: User

Code:

   1:              "have been accustomed to the carriage return and change the line once, hit a return, that is back";
   2:  
   3:              Console.WriteLine (S1);
   4:              "have been accustomed to the carriage return and a change of line once the \ r, hit a return, that is, back";
   5:              Console.WriteLine (S1);
   6:              "have been accustomed to the carriage return and a change of line once \ r \ n, knock a return, that is, back";
   7:              Console.WriteLine (S1);
   8:  
   9:              console.readline ();

Results

the difference between carriage return and line break

The difference between them is actually a return to the line.

First, history.

The origins and differences between the two concepts of carriage return "(carriage return) and" line feed ".

Symbolic ASCII code meaning

\ n 10 line break

\ r 13 Car return CR

Before the computer appeared, there was a thing called a telex typewriter (the concept of TTY under the teletype Model 33,linux/unix), which can be played 10 characters per second. But it has a problem, that is, when the line is finished, it will take 0.2 seconds to hit two characters. If there are new characters coming in this 0.2 seconds, then this character will be lost.

So, the developers think of a way to solve this problem, is to add two after each line to end the character. One is called "carriage return", which tells the typewriter to position the printhead at the left border, and the other is called "line break", telling the typewriter to move the paper down one line. This is the origin of "line break" and "carriage return", from their English name can also be seen in one or two.

Later, the computer invented, these two concepts are also like to the computer. At that time, memory was expensive, and some scientists thought it would be too wasteful to add two characters at the end of each line. So, there was a disagreement.

In Windows:

' \ R ' returns to the beginning of the current line without changing to the next line, and if the output is followed, the previous contents of the bank will be overwritten;

' \ n ' to wrap to the next line in the current position without going back to the beginning of the line;

Unix system, the end of each line only "< line >", that is, "\ n", the Windows system, the end of each line is "< Enter >< line >", that is "\ r \ n", the Mac system, the end of each line is "< Enter >", that is "\ r ";。 A direct consequence of this is that if the file under the Unix/mac system is opened in Windows, all the text will be turned into one line, and if the files in Windows are opened under Unix/mac, a ^m symbol may appear at the end of each line.

Cases:

$ Echo-en ' 12\n34\r56\n\r78\r\n ' > Tmp.txt

Viewing this file in Windws and Linux, respectively: Linux encounters a newline character ("\ n") for carriage return + line wrapping, but the carriage return is only displayed as a control character ("^m") and does not take place of carriage return. In Windows, a carriage return + newline character ("\ r \ n") will enter + line, missing a control, or another line that does not have the correct order.

The difference between \r,\n,\r\n

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.