VBScript SplitFunction


VBScript 参考手册Complete VBScript Reference

The Split function returns a zero-based one-dimensional array that contains a specified number of substrings.

Syntax

Split(expression[,delimiter[,count[,compare]]])

Parameters Description
expression Required. A string expression containing substrings and delimiters.
delimiter Optional. A character used to identify substring limits. Default is the space character.
count Optional. The number of substrings to be returned. -1 indicates that all substrings are returned.
compare Optional. Specifies the string comparison type to use.

Can take the following values:

  • 0 = vbBinaryCompare - Performs a binary comparison
  • 1 = vbTextCompare - Performs a text comparison

Examples

Example 1

<script type="text/vbscript">

a=Split("EXAMPLE is my favourite website")
for each x in a
document.write(x & "<br />")
next

</script>

The output of the above example is:

EXAMPLE
is
my
favourite
website

Try it Yourself »

Example 2

Split text using the delimiter parameter:

<script type="text/vbscript">

a=Split("Brown cow, White horse, Yellow chicken",",")
for each x in a
document.write(x & "<br />")
next

</script>

The output of the above example is:

Brown cow
White horse
Yellow chicken

Try it Yourself »

Example 3

Split text using the delimiter and count parameters:

<script type="text/vbscript">

a=Split("EXAMPLE is my favourite website"," ",2)
for each x in a
document.write(x & "<br />")
next

</script>

The output of the above example is:

EXAMPLE
is my favourite website

Try it Yourself »

Example 4

Split text using the delimiter parameter with text comparison:

<script type="text/vbscript">

a=Split("SundayMondayTuesdayWEDNESDAYThursdayFridaySaturday","day",-1,1)
for each x in a
document.write(x & "<br />")
next

</script>

The output of the above example is:

Sun
Mon
Tues
WEDNES
Thurs
Fri
Satur

Try it Yourself »

Example 5

Split text using the delimiter parameter with binary comparison:

<script type="text/vbscript">

a=Split("SundayMondayTuesdayWEDNESDAYThursdayFridaySaturday","day",-1,0)
for each x in a
document.write(x & "<br />")
next

</script>

The output of the above example is:

Sun
Mon
Tues
WEDNESDAYThurs
Fri
Satur

Try it Yourself »

VBScript 参考手册Complete VBScript Reference Other Extensions