replace \" in vb.net

2019-01-20 08:01发布

问题:

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

it doesn't work this code

name.Replace("""," ")

回答1:

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(""""," ")


回答2:

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.



回答3:

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


回答4:

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)


回答5:

I had a nasty one where try as I might, I could not get Replace() to work. In the end, it turned out the strings I was trying to clean somehow had got a completely different characters which just LOOKED like double quotes. A genius had edited a script file using Word, so "hello" became “hello”. Subtle, or what? Looking at the file with a hex editor, the opening quote was the three character value 0xe2 0x80 0x9c, and the closer was 0xe2 0x80 0x9d. No wonder the replace failed!



回答6:

'This part is to remove the " mark in the string

Dim GetDate31 As String = Date31(16).Replace(Chr(34), "")