C# escape character for "

  • Thread starter Thread starter newsgroupie
  • Start date Start date
N

newsgroupie

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
 
try

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

Chris
 
newsgroupie said:
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\"");
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top