Instr()

来源:互联网 发布:协同过滤 矩阵 编辑:程序博客网 时间:2024/06/06 14:16

Instr()

 编辑
本词条缺少名片图,补充相关内容使词条更完整,还能快速升级,赶紧来编辑吧!
Instr()函数返回字符或字符串在另一个字符串中第一次出现的位置.
中文名
Instr()
表达式
strToBeSearched, strSearchFor
性    质
函数
形    式
返回字符或字符串

目录

  1. 1 应用示范
  2. 2 应用实例

应用示范

编辑
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
0 0
原创粉丝点击