Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 392
Cranialsurge Avatar asked Jun 12 '26 10:06

Cranialsurge


1 Answers

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.

like image 149
Anthony Pegram Avatar answered Jun 14 '26 00:06

Anthony Pegram



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!