VBScript » Functions » Split

Syntax:
Split(Expression, Delimiter, Count, Compare)
Expression
The Expression argument is a string expression.
Delimiter
The optional Delimiter argument specifies the characters (including blanks) you wish to use to separate the expression. The default is a single empty space, " ".
Count
The optional Count argument specifies the number of elements to return.
Compare
The optional Compare argument must only use a constant or value from the Comparison Constants table.

The Split function separates a string into substrings and creates a one-dimensional array where each substring is an element.

Comparison Constants

CONSTANT VALUE DESCRIPTION
VBBinaryCompare 0 Binary comparison
VBTextCompare 1 Text Comparison
VBDataBaseCompare 2 Compare information inside database

Examples

Code:
<% mystring = "How now brown cow?" %>
<% myarray = Split(mystring) %>
<% =myarray(0) %>
<% =myarray(1) %>
<% =myarray(2) %>
<% =myarray(3) %>
Output:
How now brown cow?
Language(s): VBScript
Code:
<% mystring = "How now brown cow?" %>
<% myarray = Split(mystring, "ow") %>
<% =myarray(0) %>
<% =myarray(1) %>
<% =myarray(2) %>
<% =myarray(3) %>
<% =myarray(4) %>
Output:
H n br n c ?
Language(s): VBScript
Code:
<% mystring = "How now brown cow?" %>
<% myarray = Split(mystring, " ", 2) %>
<% =myarray(0) %>
<% =myarray(1) %>
Output:
How now brown cow?
Language(s): VBScript
Code:
<% mystring = "How now brown cow?" %>
<% myarray = Split(mystring, "B", 2, 1) %>
<% =myarray(0) %>
<% =myarray(1) %>
Output:
How now rown cow?
Language(s): VBScript
Code:
<% mystring = "How now brown cow?" %>
<% myarray = Split(mystring, "B", 2, VBTextCompare) %>
<% =myarray(0) %>
<% =myarray(1) %>
Output:
How now rown cow?
Explanation:

In the example, by using VBTextCompare for the Compare argument, the split occurs at the b and ignores the upper case difference between the Delimiter argument "B".

Language(s): VBScript

See Also: