Visual Basic InStr 函数

您所在的位置:网站首页 csng函数用法 Visual Basic InStr 函数

Visual Basic InStr 函数

2024-05-09 06:53| 来源: 网络整理| 查看: 265

Visual Basic 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 - 执行文本比较。 实例例子 1Module Module1 Sub Main() dim txt,pos txt="This is a beautiful day!" pos=InStr(txt,"his") Console.WriteLine(pos) End SubEnd Module运行一下

输出:

2例子 2Module Module1 Sub Main() dim txt,pos txt="This is a beautiful day!" 'A textual comparison starting at position 4 pos=InStr(4,txt,"is",1) Console.WriteLine(pos) End SubEnd Module运行一下

输出:

6例子 3Module Module1 Sub Main() dim txt,pos txt="This is a beautiful day!" 'A binary comparison starting at position 1 pos=InStr(1,txt,"B",0) Console.WriteLine(pos) End SubEnd Module运行一下

输出:

0


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3