tags:

views:

105

answers:

4

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?

+4  A: 

You can escape by doubling the quotes

g="abcd """ & a & """"

or write an explicit chr() call

g="abcd " & chr(34) & a & chr(34)
tanascius
a " at the end is missing
sushant
No, the code seems fine.
Delan Azabani
got it. thanx a lot
sushant
+2  A: 

You have to use double double quotes to escape the double quotes (lol):

g = "abcd """ & a & """"
Simon
Escaping a special character with itself is not unusual, see double backslashes in C-style languages, or double single quotes in SQL.
Tomalak
A: 

You can do like:

a="""xyz"""  
g="abcd " & a  

Or:

a=chr(34) & "xyz" & chr(34)
g="abcd " & a  
Sarfraz
+1  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
Tomalak