VBScript InStr 函数

 

定义和用法

InStr 函数可返回一个字符串在另一个字符串中首次出现的位置。

InStr 函数可返回下面的值:

  • 如果 string1 为 ""(零长度) - InStr 返回 0
  • 如果 string1 为 Null - InStr 返回 Null
  • 如果 string2 为 "" - InStr 返回 start
  • 如果 string2 为 Null - InStr 返回 Null
  • 如果 string2 没有找到 - InStr 返回 0
  • 如果在 string1 中找到 string2,InStr 返回找到匹配字符串的位置。
  • 如果 start > Len(string1) - InStr 返回 0

提示:请参阅 InStrRev 函数。

语法

InStr([start,]string1,string2[,compare])

参数描述
start可选的。规定每次搜索的起始位置。默认是搜索起始位置是第一个字符。如果已规定 compare 参数,则必须有此参数。
string1必需的。需要被搜索的字符串。
string2必需的。需搜索的字符串。
compare

必需的。规定要使用的字符串比较类型。默认是 0 。可采用下列值:

  • 0 = vbBinaryCompare - 执行二进制比较。
  • 1 = vbTextCompare - 执行文本比较。

实例

例子 1

dim txt,postxt="This is a beautiful day!"pos=InStr(txt,"his")document.write(pos)

输出:

2

例子 2

dim txt,postxt="This is a beautiful day!"'A textual comparison starting at position 4pos=InStr(4,txt,"is",1)document.write(pos)

输出:

6

例子 3

dim txt,postxt="This is a beautiful day!"'A binary comparison starting at position 1pos=InStr(1,txt,"B",0)document.write(pos)

输出:

0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值