About Me

Saturday 21 April 2012

VBScript Strings

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  with quotations, like this:
  • "Hello I am a string!"

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 null"
myString = myString & " void."
document.write(myString)
</script>

Display:

Hello there! My name is nullvoid

0 comments:

Post a Comment