VBScript Split 函数
完整的 VBScript 参考手册
Split 函数返回基于 0 的一维数组,此数组包含指定数量的子字符串。
语法
Split(expression[,delimiter[,count[,compare]]])
参数 | 描述 |
---|---|
expression | 必需。包含子字符串和分隔符的字符串表达式。 |
delimiter | 可选。用于识别子字符串界限的字符。默认是空格字符。 |
count | 可选。需被返回的子字符串的数目。-1 指示返回所有的子字符串。 |
compare | 可选。规定要使用的字符串比较类型。 可采用下列的值:
|
实例
实例 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>
以上实例输出结果:
W3CSchool
is
my
favourite
website
is
my
favourite
website
尝试一下 >>
实例 2
使用 delimeter 参数分割文本:
<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>
以上实例输出结果:
Brown cow
White horse
Yellow chicken
White horse
Yellow chicken
尝试一下 >>
实例 3
使用 delimeter 参数和 count 参数分割文本:
<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>
以上实例输出结果:
W3CSchool
is my favourite website
is my favourite website
尝试一下 >>
实例 4
使用文本比较的 delimeter 参数分割文本:
<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>
以上实例输出结果:
Sun
Mon
Tues
WEDNES
Thurs
Fri
Satur
Mon
Tues
WEDNES
Thurs
Fri
Satur
尝试一下 >>
实例 5
使用二进制比较的 delimeter 参数分割文本:
<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>
以上实例输出结果:
Sun
Mon
Tues
WEDNESDAYThurs
Fri
Satur
Mon
Tues
WEDNESDAYThurs
Fri
Satur
尝试一下 >>
完整的 VBScript 参考手册