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"));