VBScript
  1. VBScript intro
  2. VBScript basics
  3. VBScript variables
  4. VBScript procedures
  5. VBScript popup boxes
  6. VBScript conditions
  7. VBScript loops
  8. VBScript arrays
  9. VBScript strings
  10. VBScript date & time
  11. VBScript for IE 11
  12. VBScript summary

VBScript strings

A String is a grouping of characters sorrounded by double quotes such as "this is a string". With VBScript, you can manipulate strings in several ways such as joining two or more strings, printing the length of a string, and more.

This tutorial focuses on:

Creating a String

A String can be created by sorrounding text in double quotes and assigning it to a variable.

Example:
<script type="text/vbscript"> Dim aString aString= "This is a string." </script>

Printing Strings

A String can be printed by referencing the variable that stores the String by name.

Example:
<script type="text/vbscript"> Dim aString aString= "This is a string." document.write(aString) </script>
Output:
This is a string.

Joining Strings

You can join strings using the "&" (ampersand) operator. By joining strings, you can combine several strings into one or print several strings together at the same time.

Example:
<script type="text/vbscript"> Dim stringOne, stringTwo, statement, color stringOne = "Here is " stringTwo = "some text" statement = "My favorite color is " color = "green" 'join the statement and color strings into one 'and add another string to this string which is 'the period character statement = statement & color & "." 'print stringOne and stringTwo together document.write(stringOne & stringTwo) 'print a line break and the value of the statement variable document.write("<br />" & statement) </script>
Output:
Here is some text My favorite color is green.

String functions

VBScript provides various functions used for working with strings.

Example:
<html> <head> <title>String functions</title> </head> <body> <script type="text/vbscript"> Dim aString, anotherString aString = "VBScript is a scripting language." anotherString = " There are five spaces at the beginning of this string." document.write("Length of the aString string: " & len(aString)) document.write("<br />The first five characters from the aString string:" & mid(aString,1,5)) document.write("<br />The anotherString string without spaces at the beginning of it: " & ltrim(anotherString)) document.write("<br />The anotherString in all uppercase letters: " & UCase(anotherString)) </script> </body> </html>
Output:
Length of the aString string: 33 The first five characters from the aString string:VBScr The anotherString string without spaces at the beginning of it: There are five spaces at the beginning of this string. The anotherString in all uppercase letters: THERE ARE FIVE SPACES AT THE BEGINNING OF THIS STRING.
© Copyright 2013-2014 Landofcode.com
Terms of use | Privacy policy | Copyright information