Strip double quotes from a string in .NET

Even Mien picture Even Mien · Jul 24, 2009 · Viewed 188.8k times · Source

I'm trying to match on some inconsistently formatted HTML and need to strip out some double quotes.

Current:

<input type="hidden">

The Goal:

<input type=hidden>

This is wrong because I'm not escaping it properly:

s = s.Replace(""","");

This is wrong because there is not blank character character (to my knowledge):

s = s.Replace('"', '');

What is syntax / escape character combination for replacing double quotes with an empty string?

Answer

Joey picture Joey · Jul 24, 2009

I think your first line would actually work but I think you need four quotation marks for a string containing a single one (in VB at least):

s = s.Replace("""", "")

for C# you'd have to escape the quotation mark using a backslash:

s = s.Replace("\"", "");