tags:

views:

65

answers:

5

If a string has double quotes,

string str = "it is a "text""

how can I find out if the string have " or not.

And how can the double quotes be removed?

+6  A: 

To check whether it contains the quote: str.Contains("\"");

To remove the quotes: str.Replace("\"","");

thelost
Or `str.Contains(@"""")` for people who really like having lots of quotes side-by-side.
zneak
@zneak, why would I want to do that. I still have nightmares about putting quotes in strings in VB6 where """" was the only option. I am so glad I don't have to do that anymore. And making a string of things in quotes """item1""""item2"""...
Jack
+1  A: 
 string str = "it is a \"text\"";
 string str_without_quotes = str.Replace("\"", "");

Don't bother checking if it contains quotes, just replace them.

Mark
A: 
bool containsQuote = str.Contains("\"");
Jack
+1  A: 

To remove str = str.Replace("\"", String.Empty);

Hasan Khan
A: 

Don't forget good old (char)34! It can be used instead of the "\"" and the @"""" too!

SteveCav