Search code examples
vbscriptescapingstring-concatenation

Adding quotes to a string in VBScript


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?


Solution

  • You can escape by doubling the quotes

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

    or write an explicit chr() call

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