C # string literal value (escape sequence)

Source: Internet
Author: User

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"

 

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.