小白教程
所有教程
关于
Search
172.69.7.198
172.69.7.198
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Func instr”的源代码
本页内容
上一节:
Func_ubound
下一节:
Func_instrrev
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:InStr}}[[Category:vbscript ref functions|79]] = VBScript InStr 函数 = [[vbscript ref functions|完整的 VBScript 参考手册]] 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 函数。 === 语法 === <pre> InStr([start,]string1,string2[,compare]) </pre> {| class="table table-striped table-hover" !width="50%"| 参数 !width="50%"| 描述 |- | start | 可选。规定每次搜索的起始位置。默认的搜索起始位置是第一个字符(1)。如果已规定 compare 参数,则必须有此参数。 |- | string1 | 必需。需要被搜索的字符串。 |- | string2 | 必需。需要搜索的字符串表达式。 |- | compare | 可选。规定要使用的字符串比较类型。默认是 0。 可采用下列的值: * 0 = vbBinaryCompare - 执行二进制比较 * 1 = vbTextCompare - 执行文本比较 |} == 实例 1 == <sample title="" desc="" lang="vb" hererun="1"> <script type="text/vbscript"> txt="This is a beautiful day!" document.write(InStr(txt,"beautiful")) </script> </sample> 以上实例输出结果: <sample title="" desc="" lang="vb" hererun="1"> 11 </sample> == 实例 2 == 查找字母 "i",采用不同的起始位置: <sample title="" desc="" lang="vb" hererun="1"> <script type="text/vbscript"> txt="This is a beautiful day!" document.write(InStr(1,txt,"i") & "<br />") document.write(InStr(7,txt,"i") & "<br />") </script> </sample> 以上实例输出结果: <sample title="" desc="" lang="vb" hererun="1"> 3 16 </sample> == 实例 3 == 查找字母 "t",采用文本和二进制比较: <sample title="" desc="" lang="vb" hererun="1"> <script type="text/vbscript"> txt="This is a beautiful day!" document.write(InStr(1,txt,"t",1) & "<br />") document.write(InStr(1,txt,"t",0) & "<br />") </script> </sample> 以上实例输出结果: <sample title="" desc="" lang="vb" hererun="1"> 1 15 </sample> [[vbscript ref functions|完整的 VBScript 参考手册]]
返回至“
Func instr
”。
上一节:
Func_ubound
下一节:
Func_instrrev