.net 如何在字符串中包含 "

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

How to include " in a string

.netvb.netstring

提问by Kuzon

How do I include the " character in a string.

如何在字符串中包含 " 字符。

For example said = "John said "Hi""

例如 said = "John said "Hi""

回答by Darren Gosbell

You need to double up the quotes to escape them in VB

您需要将引号加倍以在 VB 中对它们进行转义

e.g. said = "John said ""Hi"""

例如 said = "John said ""Hi"""

回答by JStevens

There are also a set of Control Characters available:

还有一组控制字符可用:

Try

尝试

Dim s as String = "John said " & ControlChars.Quote & "Hi" & ControlChars.Quote

I find this much more readable than multiple quotes stacked together.

我发现这比堆叠在一起的多个引号更具可读性。

回答by Rahul Soni

Add Chr(34) to the string!

将 Chr(34) 添加到字符串中!

Something like... Console.Write("Hello " + Chr(34) + "World" + Chr(34))

类似于... Console.Write("Hello " + Chr(34) + "World" + Chr(34))

回答by Jesus Ramos

In VB.NET you must use 2 quotes: "John Said ""Hi"""

在 VB.NET 中,您必须使用 2 个引号: "John Said ""Hi"""