InStr 函数

返回某个字符串在另一字符串中的位置。

Instr 函数返回两个字符串相匹配的位置。如果在另一个字符串中未找到给定的字符串,则返回 0。

语法:


InStr ([Start As Integer,] Text1 As String, Text2 As String[, Compare])

返回值:

整数

参数:

Start: A numeric expression that marks the position in a string where the search for the specified substring starts. If you omit this parameter, the search starts at the first character of the string. The minimum allowed value is 1. The maximum allowed value is 2,147,483,648.

Text1」:要在其中进行搜索的字符串表达式。

Text2」:要搜索的字符串表达式。

Compare」: 用来定义比较类型的可选数字表达式。此参数的值可为 0 或 1。默认值 1 指定文字比较 (不区分大小写)。值 0 指定二进制比较 (区分大小写)。

为了避免运行时错误,如果省略了第一个返回参数,请不要设置 Compare 参数。

错误代码:

5 无效的过程调用

示例:


Sub ExamplePosition
Dim sInput As String
Dim iPos As Integer
    sInput = "Office"
    iPos = Instr(sInput,"v")
    Print iPos
End Sub

请支持我们!