||Since strings are delimited by double quotes, one may wonder how, exactly, one could insert double quotes within a string. For example, if you wanted to assign a string the value:|
Bob said, "Hello."
you might try the following code:
str = "Bob said, "Hello.""
Of course there are problems with the above code. How does VBScript know where the string begins and ends? Does it run from Bob to the start of Hello? That's what it looks like from the above code. To let VBScript know that you wish to insert a double quote (and not end the string), use two double quotes, in succession.
str = "Bob said, ""Hello."""
The above code will assign
Bob said, "Hello." to
str. Some people argue that placing the double quotes makes the above code a little hard to read. Those developers prefer to use
chr(34) (the ASCII code for a double quote character) in place of the double quotes like so:
str = "Bob said, " & chr(34) & "Hello." & chr(34)
Note that in place of the double quotes, the string is terminated, and a
chr(34) is concatonated to the string. Personally, I prefer the double quote method, but both the
chr(34) and double quote methods will work.