asp数组函数LBound 、UBound和Split

asp数组函数LBound 、UBound和Split已分享过asp数组函数LBound、UBound和Splitasp中设计数组的有3个VBScript函数,它们是UBound、LBound和Split。1、UBound()函数Thisfunctionwillreturnthe’index’ofthehighestelementinanarray.Theindexisbasically

大家好,欢迎来到IT知识分享网。asp数组函数LBound 、UBound和Split 

已分享过

asp数组函数LBound 、UBound和Split

asp中设计数组的有3个VBScript函数,它们是UBound、LBound和Split。
1、 UBound() 函数
This function will return the ‘index’ of the highest element in an array. The index is basically the position of the element in the array. Arrays in ASP/VBScript have a zero based starting index.
该函数返回一个数组的上界索引数。所谓的索引就是在一个数组中某元素的位置。特别注意ASP/VBScript中,数组是以0为基数开始的序列。
语法: UBound(ArrayName)
– 函数返回一个数组中最后那个元素的位置数,及上界索引。
– 请注意,如果你的数组中有10个元素的话,由于是以0为基数的,那么你的数组上界索引就是9。
举例:

<%
Dim myArray
myArray(0)=”春季”
myArray(1)=”夏季”
myArray(2)=”秋季”
myArray(3)=”冬季”
highest_element=UBound(myArray)
response.write highest_element
%>
输出结果:3
2、 LBound() 函数
语法: LBound(ArrayName)
– 返回一个数组中第一个元素,即数组的下界索引,大多数情况下等于0。
举例:

<%
Dim myArray(3)
myArray(0)=”春季”
myArray(1)=”夏季”
myArray(2)=”秋季”
myArray(3)=”冬季”
lowest_element=LBound(myArray)
response.write lowest_element
%>

输出结果: 0

3、Split() 函数

该函数常常用来将一个字符串分离(劈开)为一个数组。
语法: Split(String, Delimiter, Count)
– String 是我们将要分离(劈开)的字符串
– Delimiter 是一个隔开字符串的分隔符,通常为英文的逗号“,”
– Count 是个可选项,就是你想分离的数组的元素数

举例:

<%
Dim MyString, MyArray
MyString = “米饭,花卷,包子,面条”
MyArray = Split(MyString,”,”) ‘分隔符为英文逗号
%>

代码运行的结果是将MyString字符串分离为4元素的数组MyArray。

MyArray(0) = “米饭”
MyArray(1) = “花卷”
MyArray(2) = “包子”
MyArray(3) = “面条”
Again we could loop through the array and print out the values in each array element. In this example we’ll also incorporate the UBound function.
下面我们采用一个循环的过程代码将每个元素输出到屏幕上。本例还包含了LBound和UBound函数的使用。就是说一个简单的例子将三个函数的应用都涉及了。
<%
Dim MyString, MyArray
MyString = “米饭|花卷|包子|面条”
MyArray = Split(MyString,”|”)
For i=LBound(MyArray) to UBound(MyArray)
response.write myArray(i) & “

Next
%>

请注意上例中我采用的分隔符是“|”,实际编写代码是你可以自己变换分隔符的。

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/10860.html

(0)

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

关注微信