Visual Basci中的几个函数split(),ubound(),lbound(),instr(),mid().

Visual Basci中的几个函数:
1. Split (包含子字符串和分隔符的字符串表达式 ,[分隔符],[要返回的子字符串数],[数字值表示判别子字符串时使用的比较方式]),[]部分为可选部分。该函数返回一个以零为下标的一维数组,它包含指定数目的子字符串。
例:
dim xx as variant
xx=split("hello world"," ")'将hello world 分隔为hello和world
text1.text= xx(0) '返回hello
text2.text=xx(1) '返回world
2. Ubound (数组名),该函数返回一个 Long 型数据,其值为指定的数组维可用的最大下标
Lbound( 数组名),返回一个 Long 型数据,其值为指定数组维可用的最小下标。
例:
dim xx as variant
xx=split("hello world"," ")
text1.text=ubound(xx) '返回1
text2.text=lbound(xx) ‘返回0
3 .Instr ([start, ]string1, string2),该函数返回 Variant (Long),指定一字符串(string2)在另一字符串中(string1)最先出现的位置,如果没有找到返回0。[start,]为可选参数,表示搜索的开始位置。
例:
dim xx as string
xx="hello world"
text1.text=instr(xx,"o") '返回5
text2.text=instr(6,xx,"o") '返回8,从第6个字符开始查找
4. Mid (string, start[, length]),返回Variant (String),其中包含字符串(string)中指定长度[,length]的字符,start为开始位置。其中的[,length]为可选参数不指定长度,则返回start后的所有字符。
例:
dim xx as sting
xx="hello world"
text1.text=mid(xx,1,5)'返回hello
text2.text=mid(xx,1) '返回hello world

Published At
Categories with Web编程
Tagged with
comments powered by Disqus