VBScript Split function
Split function returns based on one dimensional array, the array contains a specified number of substrings.
grammar
Split(expression[,delimiter[,count[,compare]]])
参数 | 描述 |
---|---|
expression | 必需。包含子字符串和分隔符的字符串表达式。 |
delimiter | 可选。用于识别子字符串界限的字符。默认是空格字符。 |
count | 可选。需被返回的子字符串的数目。-1 指示返回所有的子字符串。 |
compare | 可选。规定要使用的字符串比较类型。 可采用下列的值:
|
Examples
Example 1
<script type="text/vbscript">
a=Split("W3CSchool is my favourite website")
for each x in a
document.write(x & "<br />")
next
</script>
a=Split("W3CSchool is my favourite website")
for each x in a
document.write(x & "<br />")
next
</script>
Examples of the above output:
W3CSchool
is
my
favourite
website
is
my
favourite
website
try it"
Example 2
Use delimeter text segmentation parameters:
<script type="text/vbscript">
a=Split("Brown cow, White horse, Yellow chicken",",")
for each x in a
document.write(x & "<br />")
next
</script>
a=Split("Brown cow, White horse, Yellow chicken",",")
for each x in a
document.write(x & "<br />")
next
</script>
Examples of the above output:
Brown cow
White horse
Yellow chicken
White horse
Yellow chicken
try it"
Example 3
Use delimeter parameters and count parameters split text:
<script type="text/vbscript">
a=Split("W3CSchool is my favourite website"," ",2)
for each x in a
document.write(x & "<br />")
next
</script>
a=Split("W3CSchool is my favourite website"," ",2)
for each x in a
document.write(x & "<br />")
next
</script>
Examples of the above output:
W3CSchool
is my favourite website
is my favourite website
try it"
Example 4
Delimeter parameters using text comparison text segmentation:
<script type="text/vbscript">
a=Split("SundayMondayTuesdayWEDNESDAYThursdayFridaySaturday","day",-1,1)
for each x in a
document.write(x & "<br />")
next
</script>
a=Split("SundayMondayTuesdayWEDNESDAYThursdayFridaySaturday","day",-1,1)
for each x in a
document.write(x & "<br />")
next
</script>
Examples of the above output:
Sun
Mon
Tues
WEDNES
Thurs
Fri
Satur
Mon
Tues
WEDNES
Thurs
Fri
Satur
try it"
Example 5
Using a binary comparison delimeter text segmentation parameters:
<script type="text/vbscript">
a=Split("SundayMondayTuesdayWEDNESDAYThursdayFridaySaturday","day",-1,0)
for each x in a
document.write(x & "<br />")
next
</script>
a=Split("SundayMondayTuesdayWEDNESDAYThursdayFridaySaturday","day",-1,0)
for each x in a
document.write(x & "<br />")
next
</script>
Examples of the above output:
Sun
Mon
Tues
WEDNESDAYThurs
Fri
Satur
Mon
Tues
WEDNESDAYThurs
Fri
Satur
try it"
Complete VBScript Reference