HomeASP HostingWeb DesignRegister DomainSupportAbout Us

FAQ
Support :: FAQ


ASP Split() function in action
The ASP Split() (VBScript) function is very useful and it’s often used in ASP to accomplish various tasks. You may have already guessed what is the purpose of the ASP Split() function, just by its name and you’re probably right J. The purpose of the Split() function is to split a string of characters and to insert the result into a VBScript array.

Consider the following example:

<%

sMyString = "This is a character string"

arrResult = Split(sMyString, " ")

For iCounter = 0 to Ubound(arrResult)
    Response.Write arrResult(iCounter) & "<br>"
Next

%>

The result displayed on your browser screen will look like this:

This
is
a
character
string

The first parameter taken by the Split() function is the string that has to be split – in our example the string is "This is a character string". The second parameter is the so-called delimiter, used to identify the sub-string limits. In our example the delimiter is a single white space string, but you can use any string instead. For example if you have text file with comma separated entries, then the obvious choice is to choose comma for your delimiter:

<%

sMyString = "John,Smith,12/12/1963"

arrResult = Split(sMyString, ",")

For iCounter = 0 to Ubound(arrResult)
    Response.Write arrResult(iCounter) & "<br>"
Next

%>

The example above will print the following:

John
Smith
12/12/1963


If you skip the second parameter of the VBScript Split() function, then the default value used for delimiter is single white space, exactly like in our first example above. The following lines produce equivalent results:

<%
arrResult = Split(sMyString, " ")
arrResult = Split(sMyString)
%>
© Copyright 2001-2004 Art Branch Inc.