views:

446

answers:

3

how can i replace the double quote in vb.net?

it doesn't work this code

name.Replace("""," ")
+5  A: 

You need to use a double quote within those quotes (and get the return value - String.Replace does not operate on the string itself, it returns a new string):

name = name.Replace(""""," ")
paxdiablo
That'll do the replace, but being a fragment seems to give the impression it will happen in place. It won't, a new string is returned (I'm sure *you* know that, just saying I'd make it clear in the answer).
T.J. Crowder
A: 

you should return the resultant string back to a string and also escape that double quotes with a double quote or "\"

name = name.Remove("""", String.Empty)

ydobonmai
You can't escape strings in VB.Net
Rowland Shaw
A: 

Instead of a "data link escaped" method of...

name = name.Replace("""", "")

You could be explicit and somewhat more readable...

name = name.Replace(ControlChars.DblQuote, "")

And BTW, instead of thinking of this as returning a NEW STRING; its better to think of the REPLACE as a part of the STRING Class associated with the 'name' instance. If its losing the old value of name that you do not want then simply...

Dim aNewString$ = name.Replace(ControlChars.DblQuote, "")

And 'name' will remain unchanged.

tobrien