VBScript
VBScript introduction
VBScript basics
VBScript variables
VBScript procedures
VBScript popup boxes
VBScript conditions
VBScript loops
VBScript arrays
VBScript strings
VBScript date & time
VBScript summary

Programming

Programming intro
Java

Markup

First webpage guide
HTML
XHTML

Browser scripting

Javascript
AJAX

Server scripting

PHP
ASP

Making money online

Make money online

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 lesson 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 /><br />The first five characters from 
the aString string:" & Mid(aString,1,5))

document.write("<br /><br />The anotherString string without 
spaces at the beginning of it: " & ltrim(anotherString))

document.write("<br /><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.

Practice

Online code editor
Practical examples
Practical exercises
Step-by-step tutorials

Reference

Terms glossary
Reference material

Rate this site

Rate this site
Visitor comments