Adding quotes to a string in VBScript

sushant picture sushant · May 31, 2010 · Viewed 177.1k times · Source

I have this code:

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

After running it, the value of g is abcd xyz.

However, I want quotes around the value of a in g. After running the code, g should be abcd "xyz" instead.

How can I accomplish this?

Answer

tanascius picture tanascius · May 31, 2010

You can escape by doubling the quotes

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

or write an explicit chr() call

g="abcd " & chr(34) & a & chr(34)