-
Instr()
编辑
本词条缺少
名片图,补充相关内容使词条更完整,还能快速升级,赶紧来
编辑吧!
Instr()函数返回字符或字符串在另一个字符串中第一次出现的位置.
-
中文名
- Instr() 表达式
- strToBeSearched, strSearchFor
-
性 质
- 函数 形 式
- 返回字符或字符串
目录
Instr()
函数返回字符或字符串在另一个字符串中第一次出现的位置.
表达式 Instr([start, ] strToBeSearched, strSearchFor [, compare])
允许数据类型: Start为搜索的起始值,strToBeSearched接受搜索的
字符串 strSearchFor要搜索的字符.compare比较方式(详细见ASP常数)
示范1:
<%
strText = "This is a test!!"
pos = Instr(strText, "a")
response.write pos
%>
返回结果: 9
备注:如果接受搜索的字符串中没有要搜索的字符串,则返回结果为0。
示范2:
<%
strText = "This is a test!!"
pos = Instr(strText, "b")
response.write pos
%>
返回结果: 0
计算某一目标字符串在另一字符串中出现的次数
Function CountStrings(longstring, target)
Dim position, count
position = 1
Do While InStr(
position, longstring, target)
position = InStr(position, longstring, target) + 1
count = count + 1
Loop
CountStrings = count '函数返回计算结果
End Function