Strings.InStrRev(String, String, Int32, CompareMethod) 方法
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
傳回某個字串在另一個字串中第一次出現的位置,從字串的右邊開始。
C#
public static int InStrRev (string? StringCheck, string? StringMatch, int Start = -1, Microsoft.VisualBasic.CompareMethod Compare = Microsoft.VisualBasic.CompareMethod.Binary);
C#
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
必要。 正在搜尋的字串運算式。
- StringMatch
- String
必要。 正在搜尋的字串運算式。
- Start
- Int32
選擇性。 為每一個搜尋設定以 1 起始的位置之數值運算式,從字串的左邊開始。 如果省略 Start
,則會使用 -1,表示搜尋會從最後一個字元位置開始。 從右到左進行的搜尋。
- Compare
- CompareMethod
選擇性。 數值,表示在評估子字串時要使用的比較類型。 如果省略,則會執行二進位比較。 請參閱數值的設定。
如果 | InStrRev 會傳回 |
---|---|
StringCheck 的長度為零 | 0 |
StringMatch 的長度為零 |
Start
|
StringMatch 找不到。 | 0 |
StringMatch 中找到 StringCheck | 找到第一個符合項目的位置,從字串的右邊開始。 |
Start 大於 StringMatch 的長度 | 0 |
Start
= 0 或 Start
< -1。
這個範例示範如何使用 函 InStrRev
式。
VB
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
語法不同。
自 Compare
變數可以有下列值。
常數 | 描述 |
---|---|
Binary |
執行二進位比較。 |
Text |
執行文字比較。 |
產品 | 版本 |
---|---|
.NET | Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |