如何在VB中的字符数组中插入双引号

时间:2013-09-06 15:40:52

标签: arrays vb.net character double-quotes

我正在尝试这样做,但它失败了CChar(“”“)。任何想法我尝试了CChar(”\“”)。它给出错误“字符串常量必须以双引号结束”

Dim arrayWithQuote() As Char = {CChar("a"), CChar("b"), CChar(""")}

2 个答案:

答案 0 :(得分:1)

你只需要一个额外的双引号来逃避它(你不使用\来转义vb中的字符串):

Dim arrayWithQuote() As Char = {CChar("a"), CChar("b"), CChar("""")}

正如蒂姆所指出的,你应该使用字面文字来做这类事情:

Dim arrayWithQuote() As Char = {"a"c, "b"c, """"c}

或者你可以这样做:

Dim arrayWithQuote() As Char = {"a"c, "b"c, Microsoft.VisualBasic.Chr(34)}

答案 1 :(得分:0)

尝试将字符串分隔为: -

Dim arrayWithQuote() As Char = {CChar("a"), CChar("b"), CChar("""")}