VBScript Strings
Strings are a bunch of alpha-numeric characters grouped together into
a "string" of characters. This sentence I am writing right now is an example
of a text string and it could be saved to a VBScript string variable if I wanted it to.
VBScript String Syntax
To create a string in VBScript you must surround the letters or numbers you
wish to be stringanized (that's a made up Tizag word) with quotations, like this:
VBScript String: Saving into Variables
Just like numeric values, strings in VBScript are saved to variables using
the equal operator. This example shows how to save the string "Hello there!" into
the variable myString and then use that variable with the document.write
function.
VBScript Code:
<script type="text/vbscript">
Dim myString
myString = "Hello there!"
document.write(myString)
</script>
Display:
Hello there!
VBScript String Concatenation
Often it is advantageous to combine two or more strings into one. This operation of adding a
string to another string is referred to as concatenation. The VBScript script concatenation
operator is an ampersand "&" and occurs in between the two strings to be joined. This example
will join a total of 4 strings to form a super string. Note: We only use
one variable in this example!
VBScript Code:
<script type="text/vbscript">
Dim myString
myString = "Hello there!"
myString = myString & " My name"
myString = myString & " is Frederick"
myString = myString & " Nelson."
document.write(myString)
</script>
Display:
Hello there! My name is Frederick Nelson.
Found Something Wrong in this Lesson?Report a Bug or Comment on This Lesson - Your input is what keeps Tizag improving with time! |