Remove double quotes from a string

  • Thread starter Thread starter Curious
  • Start date Start date
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!
 
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(@"\""", "");
 
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();
}
 
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
 
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.
 
Back
Top