C # string Escape walkthrough

Source: Internet
Author: User

C # escape Character:

• A special character constants quantity;
• Begins with a backslash "\" followed by one or several characters.
• Have a specific meaning, different from the original meaning of the character, it is called "escape" character.
• Primarily used to represent control codes that are not easily represented by generic characters.
• Its role is to eliminate the original meaning of the character immediately following
• Replace some special characters with a combination of ordinary characters, which is called "escape" because it changes the meaning of the original character representation.
• Denotes a character that cannot be seen with a visible character, such as ' \ n ' means a newline

Commonly used escape characters and their meanings:
\ ' Single quotes
\ "Double Quotes
\ reverse Slash
Empty
\a warning (generating peak)
\b Backspace
\f Page Change
\ n Line Change
\ r Carriage Return
\ t Horizontal tab
\v Vertical Tab


In C #, the @ says:
In C #, "c:\\temp" means that the path is c:\temp; and @ "C:\Temp" means c:\temp;

Therefore, the role of @ should be to ignore the role of escape characters.

Application examples

The root of the problem:
I get the data format of the network is JSON format, after parsing, I found all the
\\u53cc\\u6c27\\u6c34\\u4ef7\\u683c
So want to turn into

\u53cc\u6c27\u6c34\u4ef7\u683c

Looking for a long time, through the QQ group, thanks to the help of netizens!
Two methods are given:

var B = regex.replace ("\\u53cc\\u6c27\\u6c34\\u4ef7\\u683c", @ "\\u ([0-9a-f]{4})", (Match m) =>
{
Return (char) Convert.ToInt32 (m.groups[1]. Value, 16)). ToString ();
});
Console.WriteLine (b);

The second type:

Console.WriteLine (Regex.unescape ("\\u53cc\\u6c27\\u6c34\\u4ef7\\u683c"));

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.