HiveBrain v1.2.0
Get Started
← Back to all entries
patterncsharpCritical

Can I escape a double quote in a verbatim string literal?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
literaldoublequoteverbatimcanstringescape

Problem

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";

Solution

Use a duplicated double quote.

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


outputs:

this "word" is escaped

Code Snippets

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

Context

Stack Overflow Q#1928909, score: 928

Revisions (0)

No revisions yet.