Reputation: 227
How can I replace the double quote in VB.NET?
This code doesn't work:
name.Replace("""," ")
Upvotes: 20
Views: 94688
Reputation: 618
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; it's better to think of the REPLACE as a part of the STRING Class associated with the 'name' instance. If it's losing the old value of name that you do not want then simply...
Dim aNewString$ = name.Replace(ControlChars.DblQuote, "")
And the 'name' will remain unchanged.
Upvotes: 20
Reputation: 1
'This part is to remove the " mark in the string
Dim GetDate31 As String = Date31(16).Replace(Chr(34), "")
Upvotes: -1
Reputation: 51
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!
Upvotes: 0
Reputation: 15139
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)
Upvotes: 0
Reputation: 881663
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(""""," ")
Upvotes: 22