InStrRev Function [VBA]

Returns the position of a string within another string, starting from the right side of the string.

警告图标

该功能或常量可通过以下语句启用:Option VBASupport 1,该语句需要放置在模块的每个可执行程序代码的前面。


The InStrRev function returns the position at which the match was found, from the right. If the string was not found, the function returns 0.

语法:

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

返回值:

Long

参数:

Text1: The string expression that you want to search.

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

Start: Optional numeric expression that marks the position from the left in a string where the search for the specified substring starts. If you omit this parameter, the search starts at the last character of the string. The maximum allowed value is 65535.

Compare: Optional numeric expression that defines the type of comparison. The value of this parameter can be

1: The default value of 1 specifies a text comparison that is not case-sensitive.

0: The value of 0 specifies a binary comparison that is case-sensitive.

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) ' 返回 1, 搜索时区分大小写

 Print iPos 

 iPos = InStrRev(sInput,"the",10,0) ' 返回 0, 搜索时区分大小写

 Print iPos

End Sub