Skip to content

Escaping Quotes in Strings

Here’s a quick tip about embedding quotes in your string literals. Let’s say you need to put quotes inside a string. The most common way I’ve seen developers do this is with Chr(34):

Var myString As String = "Hello " + Chr(34) + "World" + Chr(34)

Some developers choose to define a constant and use that instead:

Var myString As String = "Hello " + kQuote + "World" + kQuote

But did you know you can insert a quote into your string by using two quotes instead?

Var myString As String = "Hello ""World"""

Makes the string a little more legible, doesn’t it? Learn how to handle non-visible characters in strings in the next post.

*This is an update of an older post by Thom McGrath.