InStrRev 函数 [VBA]

返回字符串在另一个字符串中的位置,从字符串的右侧开始。

warning

This constant, function or object is enabled with the statement Option VBASupport 1 placed before the executable program code in a module.


InStrRev函数从右侧返回找到匹配的位置。 如果未找到该字符串,则该函数返回0。

语法:


InStrRev (StringCheck As String, StringMatch As String [,Start As Long] [, Compare As Integer])

返回值:

Long

参数:

StringCheck: The string expression that you want to search.

StringMatch: The string expression that you want to search for.

开始」:可选的数字表达式,用于标记字符串中「从左侧开始」的位置,从该位置开始搜索指定的子字符串。 如果省略此参数,搜索将从字符串的最后一个字符开始。 允许的最大值为 65535。

比较」:可选的数字表达式,用于定义比较的类型。 该参数的值可以是

1: 默认值 1 指定不区分大小写的文本比较。

0: 值 0 指定区分大小写的二进制比较。

To avoid a run-time error, do not set the Compare parameter if the first return parameter is omitted.

错误代码:

5 无效的过程调用

示例:


Sub ExamplePosition
Dim sInput As String
Dim iPos As Integer
 sInput = "The book is on the table"
 iPos = InStrRev(sInput,"the",10,1) ' Returns 1, search is case-insensitive
 Print iPos 
 iPos = InStrRev(sInput,"the",10,0) ' Returns 0, search is case-sensitive
 Print iPos
End Sub

请支持我们!