Monke
Monke

Reputation: 55

VB.Net Using Quote Mark in Quote Marks

I want to create a text from texts. I'll show you the code.

"text"" + textbox1.text + """

And I want it to out like this

text"textbox1.text"

But It gives me errors because of the using quote marks...

Upvotes: 1

Views: 1926

Answers (2)

Dacker
Dacker

Reputation: 892

Shouldn't it be this?

"text""" + textbox1.text + """"

If I remember correctly a double double quote is how to escape a quote in VB.

In C# this would have been

"text\"" + textbox1.Text + "\""
// or (with a verbatim string)
@"text""" + textbox1.text + @""""
// more logic use of verbatim string (especially if you 
// want to create a string with multiple lines)
string.Format(@"text""{0}""", textbox1.Text);

\" means the double quote character in a string in C#

"" means the double quote character in a string in VB or in a C# verbatim string

In a verbatim string the \ doesn't escape anymore so to have a quote inside a verbatim string you also have to double it like in VB.Net (worded differently, VB.Net string are all verbatim strings)

Upvotes: 1

Idle_Mind
Idle_Mind

Reputation: 39122

Here's one option:

"text" & Chr(34) & textbox1.text & Chr(34)

Upvotes: 3

Related Questions