"Go" line break ' \ n ' and carriage return ' \ R '

Source: Internet
Author: User

Original address:

http://blog.csdn.net/silyvin/article/details/7275037

Original:

  

Before the computer appeared, there was a gadget called a telex typewriter (teletype Model 33) that could play 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.

Unix system, the end of each line only "< line >", that is "\ n", the Windows system, each line at the end of the "< newline >< Enter >", that is "\n\r", Mac system, the end of each line is "< Enter >". 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.


In ASCII, carriage returns and line feeds are different characters.   0x0a is the carriage return, that is, the cursor moves to the left of the bank; 0x0d is a newline, that is, the cursor moves to the next line.

In the DOS window press ENTER, in fact, the input of two characters 0x0a,0x0d, corresponding to C, is \ r (carriage return) \ n (newline)

In the C language
Save \ n to File
window:0d 0a
unix:0d
If you do not save to a file, it will not change.
If extracted from a file,
windows:0d 0a \ n
UNIX:0D \ n

[Tourist posted on 2008-03-27 18:55]

Enter key, that is, the keys on the keyboard, is a more useful key, in the text editing, the function of the enter is to wrap, enter the URL when the function is "go", in the execution of the DOS command, the function of the enter is to execute ...
On the standard keyboard, enter a total of 2, one on the right side of the main keyboard area, the SHIFT key on the top, one in the lower right corner of the keypad, the plus key below.

The history of the ENTER key

On the origin of the "enter", but also from the mechanical English typewriter speaking. On the typewriter, there is a part called "Word car", each input a word, "word car" forward one. When the full line, the user will push the "word car" to the starting position, then the typewriter will have two actions: "Word car" to the position, roll up a row (equivalent to "word car" down one line), in order to start entering the next line, which pushes the "word car" action called "enter". Later, on the electric typewriter, people added a direct "return" function of the key. He is called "enter".
on today's computer keyboard, "Enter" has been used "CR", "RETURN" the words, and later only unified determined as "Enter".

Enter the ASCII code

16 binary is "0x0d"
10 binary is "13"
In some languages, you can use ' \ r ' as a representation.

[Tourist posted on 2008-03-27 18:59]

If you used a mechanical typewriter, you know the difference between a carriage return and a newline ...
Line wrapping is to roll a cylinder, without changing the horizontal position.
Return is the horizontal position reset, do not scroll the drum.


But we usually press the enter in the end is the return or the line, not very clear??
See a saying: Windows under Enter is \n\r,unix under \n,mac is \ r

In MS System plain Text Format press A enter key to enter a two character, a carriage return a newline. In a Linux system, it's just a carriage return.
The above contents refer to the discussion of http://topic.csdn.net/t/20040617/23/3101951.html# and http://topic.csdn.net/t/20021113/09/1171659.html

There are also file operations at the time of programming

WB (binary) or WT (text) can also have an effect. I did an experiment (experimental. net2003)
Enter 12 in the 01.txt file and enter, and the binary that you see in UltraEdit is 0d 0a

Then the program is as follows:

int Mian ()
{FILE *FP1,*FP2,*FP3,*FP4,*FP5,*FP6;

Char a[10];
Char b[10];

FP1 = fopen ("01.txt", "R");
FP3 = fopen ("02.txt", "w");
Fread (a,sizeof (unsigned char), 8,FP1); A is 0a.
Fwrite (a,sizeof (unsigned char), 8,FP3); 02.txt is 0d 0a, the reason is that the input of the case, the newline carriage return converted to a newline, and then output when the line break will be transferred to a newline carriage return
Fclose (FP1);
Fclose (FP3);

FP2 = fopen ("01.txt", "RB");
FP4 = fopen ("03.txt", "WB");
Fread (b,sizeof (unsigned char), 8,FP2); B is 0d 0a.
Fwrite (b,sizeof (unsigned char), 8,FP4); 03.txt is 0d 0a, because the binary case of carriage return and newline (the kind of text-like conversion) does not exist
Fclose (FP2);
Fclose (FP4);

return 0;
}
It seems like the conclusion is this: in the way of reading, in text mode, enter is 0x0a; in binary mode, enter is 0x0d,0x0a.

MSDN found this: Also, in text mode, carriage return–linefeed combinations is translated into a single linefeeds on input, and L Inefeed characters is translated to carriage return–linefeed combinations on output. (in the case of input, a newline carriage return is converted to a newline, and then the output is wrapped and then converted to a newline return) when a Unicode stream-i/o function operates in text mode (the default), the source or de Stination Stream is assumed to be a sequence of multibyte characters. Therefore, the Unicode stream-input functions convert multibyte characters to wide characters. For the same reason, the Unicode stream-output functions convert wide characters to multibyte characters.

Open in binary (untranslated) mode; Translations involving Carriage-return and linefeed characters are suppressed. (The conversion of a carriage return and a newline in binary case does not exist).

One more quote: HTTP://ZHIDAO.BAIDU.COM/QUESTION/27868102.HTML?FR=QRL3

Soft and Hard return}

The hard return is ordinary we press the return to produce, it in the line breaks also plays the role which the paragraph separates.
Soft return is generated with SHIFT + Enter, it wraps, but does not change paragraph, that is, the front and back two paragraphs of text in Word belong to the same "paragraph." You will appreciate this when you apply the formatting.


Switch:

Edit-Replace, click Advanced, in the "Find what" point in the "special characters" in the manual line break, and then "Replace with" in the "special characters" in the paragraph mark, and finally click Replace All.




There is only one return enter on the keyboard, but there are two different characters of the line mark, but it is a miracle.

Our usual carriage return is a hard return, which is the small curved arrow that is produced by tapping the ENTER key in Word, which accounts for two bytes. This kind of carriage return can effectively make the paragraph mark out clearly. The text between two hard returns becomes a paragraph that can be individually set to paragraph marks without worrying about other paragraphs being affected. This is the reason why we used to use hard return: typesetting is convenient.

But the hard return also brought us trouble. If you are a web designer, or a forum Ranger, there must be this experience: when you plan to change, the line is really not flattering, line spacing is too big! In fact, this is the same as the hard return principle, but in Word and other text editor does not show its "true". But this kind of typesetting does cause a little difficulty, then we have to ask for a hard return brother: Soft return.

A soft return takes up only one byte and is a downward arrow in Word. If you copy text from a very complex web page to Word, it must not be unfamiliar to you. But it's not that easy to enter a soft return directly in Word. Because soft return is not a true paragraph mark, it is just another line, not a fragment. So it is not very conducive to typography, because it cannot be given a special format as a separate paragraph. But nonetheless, it has a pivotal position in web design.

Soft return allows the line spacing between the front and back lines to be significantly reduced, because it is not a paragraph mark, and the legal paragraph mark-hard return to distinguish. The hard return HTML code is <p>. </p&gt, the content of the paragraph is sandwiched inside, and the soft return code is very lean:<br>. So in the Web page want to use a soft return, just switch to the code page, type the soft return code.
Let me tell you the conversion of carriage return when different editor text is copied to each other.

As the Earth knows, if the text of the page is copied to Word, the hard return becomes a curved arrow, and the soft return becomes the downward arrow. As a result, friends who are accustomed to using Word to edit text are not accustomed to the uncomfortable situation.

It is also true that text in Word is copied to a Web page. You can say that word is compatible with Web pages, or how do you get a "Save as a Web page" option?

Notepad is also the more you touch the editor. But in recent years, with the development of society and the various drawbacks of Notepad, many people have limbo it. I can only express regret for this, because the function of Notepad itself is not replaced by other editors of the advantages. When you copy the text of the Web page again, you may want to paste it into Notepad and try it. Haha, no matter what the Web designer used to enter, now has become a kind of carriage return! What, you don't believe me? Let's see: The soft return becomes the normal carriage return, and the hard return turns into two normal carriage returns. You copy the text from Notepad to Word, the carriage return in Notepad is all turned into a hard return! You then copy the text from the Notepad to the Web editor, all the carriage return will become a soft return!!

[Tourist posted on 2008-03-27 19:00]

\ n is a newline, English is Linefeed,ascii code is 0xA.
\ r is the carriage return, English is carriage return, ASCII code is 0xD.

"Go" line break ' \ n ' and carriage return ' \ R '

Related Article

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.