Differences between \ r, \ n, \ r \ n
Code:
1: string s1 = "Get used to carriage return and line feed once. \ n. Press A enter key, that is, return ";
2:
3: Console.WriteLine(s1);
4: s1 = "Get used to pressing the carriage return and line feed once. \ r. Press the Enter key, that is, return ";
5: Console.WriteLine(s1);
6: s1 = "Get used to pressing the carriage return and line feed once. \ r \ n. Press the Enter key, that is, return ";
7: Console.WriteLine(s1);
8:
9: Console.ReadLine();
Result
Differences between carriage return and line feed
The difference between them is actually a question of carriage return and line feed.
History
The origins and differences between Carriage Return and Line Feed.
Symbol ASCII code meaning
\ N 10 line feed
\ R 13 press ENTER CR
Before the computer appeared, there was a kind of thing called Teletype Model 33, which also came from the tty concept in Linux/Unix. It can contain 10 characters per second. But there is a problem, that is, when a line breaks a line, it takes 0.2 seconds, just two characters. If a new character is passed in the 0.2 s, the character will be lost.
As a result, the developers thought of a way to solve this problem, that is, adding two end characters after each line. One is "enter", which tells the typewriter to position the print head on the left boundary, and the other is "line feed", which tells the typewriter to move the paper down one line. This is the source of "line feed" and "Carriage Return". They can also be seen in their English names.
Later, computers were invented, and these two concepts were invented on computers. At that time, memory was very expensive. Some scientists thought it would be too waste to add two characters at the end of each line. Just add one character. As a result, there were differences.
In Windows:
'\ R': Press enter to return to the beginning of the current row, instead of switching to the next row. If it is output, the previous contents of the row will be overwritten one by one;
'\ N' line feed, switch to the next line at the current position, instead of returning to the first line;
In Unix systems, each line ends with "<line feed>", that is, "\ n". In Windows systems, each line ends with "<press enter> <line feed> ", that is, "\ r \ n"; in Mac systems, the end of each line is "<press enter>", that is, "\ r ";. One direct consequence is that if a file in Unix/Mac is opened in Windows, all the text will be changed to a line; if a file in Windows is opened in Unix/Mac, A ^ M symbol may be added at the end of each line.
Example:
$ Echo-en'12 \ n34 \ r56 \ n \ r78 \ r \ n'> tmp.txt
View this file in Windws and Linux respectively. We can see that in Linux, line breaks ("\ n") are used to press ENTER + line breaks, the carriage return is only displayed as a control character ("^ M") without carriage return. In windows, carriage return + line feed ("\ r \ n") is required to press ENTER + line feed. If a control character is missing or the order is incorrect, the line cannot start correctly.
For an essential analysis, see the differences between carriage return line feed (\ n \ r) and line feed (\ r) in C ++.
Note:
When parsing the content of a text or other format file, it is often necessary to determine the place where the carriage return line is wrapped. In this case, you must determine that "\R\ N "must determine" \ n ".
When writing a program, you may get a line and trim it out '\R'To get the string you need.