替换 vb.net 中的 "

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2452906/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 14:46:58  来源:igfitidea点击:

replace " in vb.net

vb.netreplaceescaping

提问by Mark

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

如何替换 VB.NET 中的双引号?

This code doesn't work:

此代码不起作用:

name.Replace("""," ")

回答by paxdiablo

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):

您需要在这些引号中使用双引号(并获取返回值 - String.Replace 不对字符串本身进行操作,它返回一个新字符串):

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

回答by tobrien

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...

顺便说一句,不要将其视为返回新字符串;最好将 REPLACE 视为与“名称”实例关联的 STRING 类的一部分。如果它失去了您不想要的旧名称值,那么只需...

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

And the 'name' will remain unchanged.

并且“名称”将保持不变。

回答by GGSoft

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

回答by user3704779

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!

我有一个讨厌的人,Replace()尽我所能,我无法上班。最后,结果我试图清理的字符串以某种方式得到了一个完全不同的字符,它们看起来像双引号。一位天才使用 Word 编辑了一个脚本文件,因此"hello"变成了“hello”. 微妙的,还是什么?用十六进制编辑器查看文件,开头的引号是三个字符的 value 0xe2 0x80 0x9c,靠近的是0xe2 0x80 0x9d. 难怪更换失败!

回答by Ashish Gupta

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)

回答by user9286728

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

'这部分是去掉字符串中的"标记

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