1, usually directly write the string has the escape character is preceded by "@" can solve:
such as: string str = @ "Please confirm the data is wrong!" \ r \ n Interrupt program operation. ";
The actual deposit in STR is "Please confirm the data is wrong!" \\r\\n interrupt the program to run. "
2. What if the contents of the string variable are directly carried with the escape character?
For example, if STR is already in existence, "Please confirm the data is wrong!" \ r \ n Interrupt program operation. "Content.
At this point, the actual contents of the Str in the \ R and \ n is the escaped content, not the "\ r" or "\ n" character.
So if you want to change \ r or \ n to \\r or \\n, you will find the value after escaping, but the escaped value is often not a display character.
3, first to understand the escaped character in C # expression method.
The ASCII code can certainly represent this escaped non-display character, which is expressed in C # as follows:
Char Hex Oct Dec C # Presentation method
such as: Carriage return CR 0D 015 x0d
Line break LF 0A 012 x0a
BACKSPACE bar BS 010 8 x08
ESC key ESC 1 B 033 x1b
4. Now to replace the \ R and \ n in str with \ R and \\n:
After escaping the \ R is: \x0d escaped after \ n is: \x0a
String strtemp = str. Replace ("\x0a", "\\n"). Replace ("\x0d", "\\r");
The content in the result strtemp is "Please confirm the data is wrong!" \\r\\n interrupt the program to run. "
The substitution method of the literal character in the string variable