InStr 函数可返回一个字符串在另一个字符串中首次出现的位置。
InStr 函数可返回下面的值:
提示:请参阅 InStrRev 函数。
InStr([start,]string1,string2[,compare])
| 参数 | 描述 |
|---|---|
| start | 可选的。规定每次搜索的起始位置。默认是搜索起始位置是第一个字符。如果已规定 compare 参数,则必须有此参数。 |
| string1 | 必需的。需要被搜索的字符串。 |
| string2 | 必需的。需搜索的字符串。 |
| compare | 必需的。规定要使用的字符串比较类型。默认是 0 。可采用下列值:
|
dim txt,pos txt="This is a beautiful day!" pos=InStr(txt,"his") document.write(pos)
输出:
2
dim txt,pos txt="This is a beautiful day!" 'A textual comparison starting at position 4 pos=InStr(4,txt,"is",1) document.write(pos)
输出:
6
dim txt,pos txt="This is a beautiful day!" 'A binary comparison starting at position 1 pos=InStr(1,txt,"B",0) document.write(pos)
输出:
0
© 2008 woyouxian.net 版权所有 Contact Us