Let's say this is the code:
a="xyz"
g="abcd " & a
So now the value of g
is abcd xyz
. I want quotes around xyz i.e g
should be abcd "xyz"
How do I do that?
Let's say this is the code:
a="xyz"
g="abcd " & a
So now the value of g
is abcd xyz
. I want quotes around xyz i.e g
should be abcd "xyz"
How do I do that?
You can escape by doubling the quotes
g="abcd """ & a & """"
or write an explicit chr()
call
g="abcd " & chr(34) & a & chr(34)
You have to use double double quotes to escape the double quotes (lol):
g = "abcd """ & a & """"
You can do like:
a="""xyz"""
g="abcd " & a
Or:
a=chr(34) & "xyz" & chr(34)
g="abcd " & a
I usually do this:
Const Q = """"
Dim a, g
a = "xyz"
g = "abcd " & Q & a & Q
If you need to wrap strings in quotes more often in your code and find the above approach noisy or unreadable, you can also wrap it in a function:
a = "xyz"
g = "abcd " & Q(a)
Function Q(s)
Q = """" & s & """"
End Function