开发者

replace " in vb.net

How can I replace the double quote in VB.NET?

This code doesn't work:

name开发者_高级运维.Replace("""," ")


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


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.


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


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)


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!


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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜