469,343 Members | 5,377 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

C# escape character for "

Hi Newsgroupies,

Please could someone tell me the escape character for " (double quote)
in a string.Format(...) method as \x22 doesn't work as it comes out as
\" in the result.

i.e. string.Format("you say \x22goodbye\x22 and I say \x22hello\x22");

....comes out as...

you say \"goodbye\" and I say \"hello\"
Many thanks,

Newsgroupie, UK
Nov 16 '05 #1
3 41628
try

string.Format("you say \"goodbye\" and I say \"hello\"");

Chris

"newsgroupie" <ne*********@nospam.com> wrote in message
news:Me**************@rjmeltd.demon.co.uk...
Hi Newsgroupies,

Please could someone tell me the escape character for " (double quote) in
a string.Format(...) method as \x22 doesn't work as it comes out as \" in
the result.

i.e. string.Format("you say \x22goodbye\x22 and I say \x22hello\x22");

...comes out as...

you say \"goodbye\" and I say \"hello\"
Many thanks,

Newsgroupie, UK

Nov 16 '05 #2
newsgroupie <ne*********@nospam.com> wrote:
Please could someone tell me the escape character for " (double quote)
in a string.Format(...) method as \x22 doesn't work as it comes out as
\" in the result.

i.e. string.Format("you say \x22goodbye\x22 and I say \x22hello\x22");

...comes out as...

you say \"goodbye\" and I say \"hello\"


No it doesn't. It may look that way in the debugger, but that's just
the debugger fooling you. (It's attempting to help you, and failing
dismally.)

Try the following:

using System;

class Test
{
static void Main()
{
Console.WriteLine ("you say \x22goodbye\x22 and I say \x22hello\x22");
}
}

(Line outdented just to get it in easily :)

Note that you can also use \", eg

Console.WriteLine ("you say \x22goodbye\" and I say \"hello\"");

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3
The problem was that the watch window shows the escape character but
when you send the string to the output window the escape character is
not shown

In message <u7*************@TK2MSFTNGP11.phx.gbl>, Christopher Kimbell
<c_*******@online.nospam> writes
try

string.Format("you say \"goodbye\" and I say \"hello\"");

Chris

"newsgroupie" <ne*********@nospam.com> wrote in message
news:Me**************@rjmeltd.demon.co.uk...
Hi Newsgroupies,

Please could someone tell me the escape character for " (double quote) in
a string.Format(...) method as \x22 doesn't work as it comes out as \" in
the result.

i.e. string.Format("you say \x22goodbye\x22 and I say \x22hello\x22");

...comes out as...

you say \"goodbye\" and I say \"hello\"
Many thanks,

Newsgroupie, UK



--
newsgroupie
Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Steve | last post: by
3 posts views Thread by Steve | last post: by
6 posts views Thread by HK guy | last post: by
15 posts views Thread by pkaeowic | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | 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.