Remove double quotes from a string

C

Curious

Hi,

I have a string that contains extra double quotes around it.
Specifically, it's

"\"USD\""

How can I get rid of the double quotes in the string (so that it'll be
"USD")?

Thanks!
 
J

Jesse Houwing

Hello Curious,
Hi,

I have a string that contains extra double quotes around it.
Specifically, it's

"\"USD\""

How can I get rid of the double quotes in the string (so that it'll be
"USD")?

Thanks!

string cleaned = original.Replace(@"\""", "");
 
F

Family Tree Mike

Curious said:
Hi,

I have a string that contains extra double quotes around it.
Specifically, it's

"\"USD\""

How can I get rid of the double quotes in the string (so that it'll be
"USD")?

Thanks!


Use string.Replace()...

static void Main(string[] args)
{
string s = "\"USD\"";
Console.WriteLine(s);
Console.WriteLine(s.Replace("\"", ""));
Console.ReadLine();
}
 
C

Cor Ligthert[MVP]

Hi,

For those using VB and don't know that you use C#

a = a.Replace("""","")

In the way you ask it, it is typical a C# language question but not
recognizable for VB users, did you know there is a special newsgroup for
that?

Cor
 
J

Jesse Houwing

Hello Curious,
Why do you use @? What's difference between using it and not using it?

It's called a Verbatim String (see http://msdn.microsoft.com/en-us/library/aa691090.aspx).
It is a different way to write strings in C#, allowing you to ignore the
\'s in a string. It does require one to double up "s in a string so that
they are properly escaped (just like in VB.NET).

Depending on if you have more "s or more \'s in your string you can choose
between them.
 

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

Top