tags:

views:

1338

answers:

8

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?

+10  A: 
s = s.Replace("\"", "");

You need to use the \ to escape the double quote character in a string.

David
+2  A: 

You have to escape the double quote with a backslash.

s = s.Replace("\"","");
Jake Pearson
+7  A: 

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("\"", "");
Joey
+1 for reading the tags and answering for **both** C# and VB.NET, unlike most folks :)
MarkJ
+2  A: 
s = s.Replace("\"",string.Empty);
Steve Gilham
+5  A: 

You can use either of these:

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

...but I do get curious as to why you would want to do that? I thought it was good practice to keep attribute values quoted?

Fredrik Mörk
Seconding this question... I'd like to know as well.
JAB
I'm using the HTML Agility Pack to find a certain link, and then I need to remove a value in that link from the HTML text. The HTML Agility Pack quotes the attribute values, but the original HTML is not quoted. (And all this for one test.)
Even Mien
+2  A: 

c#: "\"", thus s.Replace("\"", "")

vb/vbs/vb.net: "" thus s.Replace("""", "")

svinto
+1 for reading the tags and answering for **both** C# and VB.NET, unlike most folks :)
MarkJ
A: 
s = s.Replace( """", "" )

Two quotes next to each other will function as the intended " character when inside a string.

Mike
+1  A: 

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

gHeidenreich