When creating or displaying a string, its text must be enclosed in double quotation marks to indicate the start and end of the string. These double quotation marks are not displayed, which raises a good question: What should I do if I want to display double quotation marks?
To display double quotation marks, Java creates a special encoding \ ", which can be placed in a string. When this encoding is encountered in a string, replace it with double quotation marks. For example, see the following example:
System. Out. println ("Jane Campion directed \" the piano \ "in 1993 .");
This sectionCodeThe following content is displayed:
Jane Campion directed "The Piano" in 1993.
You can use this method to insert multiple special characters into the string. These special characters are listed below. Note that each character is preceded by a backslash.
Special characters |
Display |
\' |
Single quotes |
\" |
Double quotation marks |
\/ |
Backslash |
\ T |
Tab |
\ B |
Return character |
\ R |
Carriage Return |
\ F |
Paper break |
\ N |
Line Break |
A line break is used to display text after a line break at the beginning of the next line. See the following example:
System. Out. println ("Music by \ nmichael Nyman ");
This statement will display the following content:
Music
Michael Nyman
Address character: \=> \\
\\=>\\\\
http://blog.csdn.net/lsd123/article/details/2974200