When you're first getting started in VBScript, one of the most confusing
things is how to use the " character within a string. Since
VBScript uses " as its string delimiter, if you try and use one
inside of a string, it thinks the string is ending and will usually give
you an error since it tries to interpret the rest of the string as a
VBScript command.
This leads many developers to use Chr(34) to build their strings like this:
<%
Response.Write "He said " & Chr(34) & "ASP Rocks!" & Chr(34) & " and left."
%>
While that works fine, it requires you to break out into VBScript and
then back into the string in order to continue and VBScript actually
has to do some work to concatenate the pieces together. On top of it all
you have to remember that it's character 34! Try this alternative:
<%
Response.Write "He said ""ASP Rocks!"" and left."
%>
I don't like typing more then I have to and I like to be able to
read my code. Maybe it's just me, but I feel this is much more
readable and I save typing on top of it all!
Oh and another quick tip... if you get confused about how many "
characters you need, count them... there should always be an
even number on any given line.
(So is that's a sub-quick tip or a quick quick tip?!?)
If you have a tip you would like to submit, please send it to:
webmaster@asp101.com.