ASP Vbscript Split String into Array Examples

Updated on 22 Feb 2012,
Published on 31 Jul 2008

In the previous article ASP Vbscript split string function we discussed about the syntax and parameters of the vbscript split function. Now we will learn with the help of examples: how to split string into array? Vbscript split function returns vbscript array having substrings stored at each index separated from the specified delimiter character. Following are the examples of vbscript split string function with different combinations of parameters to split the string.

Classic ASP VbScript String Functions Examples:

You can see the live samples and examples of Classic ASP VbScript String functions from the following links:

Examples for ASP Vbscript Split String into Array

Example 1
<%
' global variable to store string value
Dim myString

' comma separated string value assigned to the variable
myString = "str1,str2,str3,str4,str5"

' variable to store the result of Split function
Dim myArray

' split function with delimiter parameter as comma ","
myArray = Split(myString,",")
 
Dim counter
 
For counter = 0 To UBound(myArray)
    Response.Write(myArray(counter) & "<br />")
Next

%>
Example 2
<%
' string values having white space in place of comma
myString = "str1 str2 str3 str4 str5"

' split function with no delimiter defined
' by default delimiter is white space
myArray = Split(myString)
 
For counter = 0 To UBound(myArray)
    Response.Write(myArray(counter) & "<br />")
Next

%>
Example 3
<%
' string values having white space in place of comma
myString = "str1 str2 str3 str4 str5"

' split function with delimiter = " " single space
' count parameter = 2
' returns 2 substrings
myArray = Split(myString," ",2)

For counter = 0 To UBound(myArray)
    Response.Write(myArray(counter) & "<br />")
Next

%>
Example 4
<%
' string values having white space in place of comma
myString = "str1 str2 str3 str4 str5"

' split function with delimiter = " " single space
' count parameter = 2
' compare = vbBinaryCompare, for binary comparison approach
myArray = Split(myString," ",2,vbBinaryCompare)

For counter = 0 To UBound(myArray)
    Response.Write(myArray(counter) & "<br />")
Next

%>

Output:

You can see the output of above discussed code from the following link:

String Split Function

Continue to next tutorial: Vbscript StrComp Function To Compare Strings to learn how to compare two string values.

1 Responses to "ASP Vbscript Split String into Array Examples"
Lorie
Thanks for this!
Leave a Comment
* required
* required
* will not be published
* optional
* hint: http://www.example.com
  • Subscribe via Email