Question

I am trying to do this but it fails with the CChar("""). Any ideas I tried CChar("\""). It gives the error "String constants must end with a double quote"

Dim arrayWithQuote() As Char = {CChar("a"), CChar("b"), CChar(""")}
Was it helpful?

Solution

You just need an extra double quote to escape it (you don't use \ to escape a string in vb):

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

As Tim Pointed out you should use char literals to do this sort of thing:

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

Alternatively you could do this:

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

OTHER TIPS

Try delimiting the string as:-

Dim arrayWithQuote() As Char = {CChar("a"), CChar("b"), CChar("""")}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top