double quote in verbatim string

  • Thread starter Thread starter fred
  • Start date Start date
Also, remember you can use @ if you don't want to have to escape certain
characters (e.g. backslashes)

Thus, @"C:\Temp" is equivalent to "C:\\Temp" as both are interpreted as
C:\Temp. That won't help you for double-quotes, of course, since an
unescaped double-quote will be interpreted as a delimiter. So you have to
escape it just as Pete indicates. But the @ is useful for other string
literals.

--
Kai Brinkmann [MSFT]

Please do not send e-mail directly to this alias. This alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Kai Brinkmann said:
Also, remember you can use @ if you don't want to have to escape certain
characters (e.g. backslashes)

Thus, @"C:\Temp" is equivalent to "C:\\Temp" as both are interpreted as
C:\Temp. That won't help you for double-quotes, of course, since an
unescaped double-quote will be interpreted as a delimiter. So you have to
escape it just as Pete indicates. But the @ is useful for other string
literals.

No, you *don't* have to escape it that way - you can embed double
quotes in verbatim string literals (which was what the OP was asking
about) by doubling them up:

string x = @"before quote "" after quote";
 
Back
Top