Strings.InStrRev(String, String, Int32, CompareMethod) 方法

定义

返回某一字符串从另一字符串的右侧开始算起第一次出现的位置。Returns the position of the first occurrence of one string within another, starting from the right side of the string.

public static int InStrRev (string StringCheck, string StringMatch, int Start = -1, Microsoft.VisualBasic.CompareMethod Compare = Microsoft.VisualBasic.CompareMethod.Binary);
static member InStrRev : string * string * int * Microsoft.VisualBasic.CompareMethod -> int
Public Function InStrRev (StringCheck As String, StringMatch As String, Optional Start As Integer = -1, Optional Compare As CompareMethod = Microsoft.VisualBasic.CompareMethod.Binary) As Integer

参数

StringCheck
String

必需。Required. 搜索的 String 表达式。String expression being searched.

StringMatch
String

必需。Required. 搜索的字符串表达式。String expression being searched for.

Start
Int32

可选。Optional. 数值表达式,设置从字符串左侧开始进行的每个搜索的起始位置(从一开始计数)。Numeric expression setting the one-based starting position for each search, starting from the left side of the string. 如果省略 Start,则使用 -1,它表示搜索从最后一个字符位置开始。If Start is omitted then -1 is used, meaning the search begins at the last character position. 然后搜索从右到左继续进行。Search then proceeds from right to left.

Compare
CompareMethod

可选。Optional. 数值,指示对子字符串求值时使用的比较类型。Numeric value indicating the kind of comparison to use when evaluating substrings. 如果省略,就会执行二进制比较。If omitted, a binary comparison is performed. 具体的值请参见"设置"。See Settings for values.

返回

如果If InStrRev 返回InStrRev returns
StringCheck 的长度为零 StringCheck is zero-length 00
StringMatch 的长度为零 StringMatch is zero-length Start
未找到 StringMatch StringMatch is not found 00
StringMatch 中找到 StringCheck StringMatch is found within StringCheck 从字符串的右侧开始找到的第一个匹配项的位置。Position at which the first match is found, starting with the right side of the string.
Start 大于 StringMatch 的长度 Start is greater than length of StringMatch 00
.

异常

Start = 0 或 Start < -1。Start = 0 or Start < -1.

示例

此示例演示如何使用 InStrRev 函数。This example demonstrates the use of the InStrRev function.

Dim testString As String = "the quick brown fox jumps over the lazy dog"
Dim testNumber As Integer
' Returns 32.
testNumber = InStrRev(testString, "the")
' Returns 1.
testNumber = InStrRev(testString, "the", 16)

注解

请注意,InStrRev 函数的语法与 InStr 函数的语法不同。Note that the syntax for the InStrRev function is not the same as the syntax for the InStr function.

Compare 参数可以具有下列值。The Compare argument can have the following values.

返回的常量Constant 描述Description
Binary 执行二进制比较。Performs a binary comparison.
Text 执行文本比较。Performs a textual comparison.

适用于

另请参阅