During program development, we often encounter the use of escape sequences in the literal values of strings. The following table lists the complete escape sequences for reference:
Escape Sequence List
Escape Sequence |
Generated characters |
Unicode value of a character |
\' |
Single quotes |
Zero X 0027 |
\" |
Double quotation marks |
Zero X 0022 |
\\ |
Backslash |
0x005c |
\ 0 |
Null |
Zero x 0000 |
\ |
Warning (generate beep) |
Zero X 0007 |
\ B |
Return |
Zero X 0008 |
\ F |
Form feed |
0x000c |
\ N |
Line feed |
0x000a |
\ R |
Enter |
0x000d |
\ T |
Horizontal Tab |
Zero X 0009 |
\ V |
Vertical Tab |
0x000b |
The "Unicode value" column in the table is the hexadecimal value of the character in the Unicode Character Set. You can use Unicode escape sequences to specify Unicode characters. The Escape sequences contain standard \ characters, followed by a U and a 4-digit hexadecimal value (for example, 4 digits after X in the table ).
The following strings are equivalent:
"Karli \'s string ."
"Karli \ u0027s string ."
Obviously, Unicode escape sequences are more useful.
You can also specify a string literally, that is, all characters between two double quotes are included in the string, including the character at the end of the line and the character to be escaped. The only exception is the escape of double quotation marks. They must be specified to avoid ending the string. Therefore, you can add a @ character before the string:
@ "Verbatim string literal ."
You can specify this string in general mode, but you need to use the following method:
@ "A short list:
Item 1
Item2"
The character string specified by word is very useful in the file name because a large number of backslash characters are used in the file name. If a common string is used, two backslashes must be used in the string. For example:
"C: \ temp \ mydir \ myfile.doc"
This code is easier to read with the string literal value specified by words. The following string is equivalent to the above one:
@ "C: \ temp \ mydir \ myfile.doc"