Reputation: 6184
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?
Upvotes: 3
Views: 17146
Reputation: 29216
use \ to escape any characters. so, if you want to print the \ character, use \\
Upvotes: 0
Reputation: 23841
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\\\"");
Upvotes: 1
Reputation: 126854
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.
Upvotes: 3
Reputation: 907
This may be helpful: http://msdn.microsoft.com/en-us/library/aa691090%28v=vs.71%29.aspx
Upvotes: 0