ASP判断是否包含字符串(InStr 函数)

asp使用Instr函数来判断一字符串中是否包含另一字符串。

InStr 函数

返回某字符串在另一字符串中第一次出现的位置。

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

参数

start

可选项。用于设置每次搜索的开始位置。如果省略,将从第一个字符的位置开始搜索。如果 start 包含 NULL,则会出现错误。如果已指定 compare,则必须要有 start 参数。

string1

必选项。接受搜索的字符串表达式。

string2

必选项。要搜索的字符串表达式。

compare

可选项。指示在计算子字符串时使用的比较类型的数值。有关数值,请参阅“设置”部分。如果省略,将执行二进制比较。

设置

compare 参数可以有以下值:

常数描述
vbBinaryCompare0执行二进制比较。
vbTextCompare1执行文本比较。

返回值

InStr 函数返回以下值:

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

说明

下面的示例利用 InStr 搜索字符串:

Dim SearchString, SearchChar, MyPos
SearchString ="XXpXXpXXPXXP"       ' String to search in.
SearchChar = "P"       ' Search for "P".
MyPos = Instr(4, SearchString, SearchChar, 1)
   ' A textual comparison starting at position 4. Returns 6.
MyPos = Instr(1, SearchString, SearchChar, 0)   ' A binary comparison starting at position 1. Returns 9.    
MyPos = Instr(SearchString, SearchChar)   ' Comparison is binary by default (last argument is omitted). Returns 9.
MyPos = Instr(1, SearchString, "W")   ' A binary comparison starting at position 1. Returns 0 ("W" is not found).

注意 InStrB 函数使用包含在字符串中的字节数据,所以 InStrB 返回的不是一个字符串在另一个字符串中第一次出现的字符位置,而是字节位置。

注:使用instr函数时必须给两个字符串加上双引号

如:instr(1,”abcd“,”bc“,1)正确,instr(1,abcd,bc,1)则错误。

转载于:https://www.cnblogs.com/hackhu/archive/2007/11/24/971399.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值