469,282 Members | 2,075 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

double quote in verbatim string

Hi,

is there a way to put " (double quote) into a verbatin
string?

thank you
Nov 16 '05 #1
4 24018
Use \"
as follows:

string myString = "This string has \"quotes\" in it";
"fred" <an*******@discussions.microsoft.com> wrote in message
news:18****************************@phx.gbl...
Hi,

is there a way to put " (double quote) into a verbatin
string?

thank you

Nov 16 '05 #2
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.

"Pete Davis" <pd******@NOSPAM.hotmail.com> wrote in message
news:m6********************@giganews.com...
Use \"
as follows:

string myString = "This string has \"quotes\" in it";
"fred" <an*******@discussions.microsoft.com> wrote in message
news:18****************************@phx.gbl...
Hi,

is there a way to put " (double quote) into a verbatin
string?

thank you


Nov 16 '05 #3
Kai Brinkmann [MSFT] <ka******@online.microsoft.com> wrote:
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";

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
fred <an*******@discussions.microsoft.com> wrote:
is there a way to put " (double quote) into a verbatin
string?


See http://www.pobox.com/~skeet/csharp/s....html#literals

(Basically, double the quote.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Ernie | last post: by
4 posts views Thread by ouch | last post: by
9 posts views Thread by Steven Blair | last post: by
1 post views Thread by fred | last post: by
3 posts views Thread by Ant | last post: by
2 posts views Thread by =?Utf-8?B?QWFyb24=?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.