vb.net 如何将包含双引号的数据放入字符串变量中?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7767037/
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 15:43:48  来源:igfitidea点击:

How to put data containing double-quotes in string variable?

vb.net

提问by Manikandan Thangaraj

Possible Duplicate:
replace " in vb.net

可能的重复:
在 vb.net 中替换“

How to put data containing double-quotes in string variable? Aug 01, 2003 02:30 AM | LINK

如何将包含双引号的数据放入字符串变量中?2003 年 8 月 1 日上午 02:30 | 关联

I need to store a string that contains words in double quotes. The complete string data is presented to the variable in double quotes, but the next double quotes within the data ends the string and the remaining text gives a syntax error. How can I place literal double-quotes in a string variable? For example:

我需要存储一个包含双引号单词的字符串。完整的字符串数据以双引号提供给变量,但数据中的下一个双引号结束字符串,其余文本给出语法错误。如何在字符串变量中放置文字双引号?例如:

Dim MyVar as string = "stm_bm(["menu53d0",400,"","blank2.gif",0,"","",0,0,250,0,1000,1,0,0,""],this);"

回答by Sai Kalyan Kumar Akshinthala

You can escape (this is how this principle is called) the double quotes by prefixing them with another double quote. You can put them in a string as follows:

您可以通过在双引号前加上另一个双引号来转义(这就是该原则的名称)。您可以将它们放在一个字符串中,如下所示:

Dim MyVar as string = "some text ""hello"" "

This will give the MyVarvariable a value of some text "hello".

这将使MyVar变量的值为some text "hello"