How do I include escape sequences in a string variable
I have a type with a string property called 'TestValue' that contains a string that includes characters that are escape sequences for c#. e.g. "blah\"". I need these characters to print out to the console as well.
Console.WriteLine(obj.TestValue);
// prints only blah"
When I hover over that variable开发者_如何学编程 in the debugger I can see the exact string "blah\"", but when printed out to the console, only blah" shows up, I want blah\" to show up.
How can I get this to work?
Choose one: @"blah\"""
or "blah\\\""
@
denotes a verbatim string, but you still need to escape a double quote by doubling it up. Or you can simply escape the \
by doubling it.
You can find in this page the escape sequences which include Backslash and Double quotation mark. So, you have to escape them both by a backslash like the following:
Console.WriteLine("Blah\\\"");
This may be helpful: http://msdn.microsoft.com/en-us/library/aa691090%28v=vs.71%29.aspx
use \ to escape any characters. so, if you want to print the \ character, use \\
精彩评论