Monday, 8 January 2018

c# - Can I escape a double quote in a verbatim string literal?

itemprop="text">

In a verbatim string literal (@"foo")
in C#, backslashes aren't treated as escapes, so doing \" to get a double quote doesn't
work. Is there any way to get a double quote in a verbatim string
literal?



This understandably doesn't
work:




string foo =
@"this \"word\" is escaped";


Answer




Use a duplicated double
quote.



@"this ""word"" is
escaped";


outputs:




class="lang-none prettyprint-override">this "word" is
escaped

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print ...