Strings.InStrRev(String, String, Int32, CompareMethod) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
回傳一個字串首次出現在另一個字串中的位置,從字串的右側開始。
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
Optional. 數值表達式設定每個搜尋的一基起始位置,從字串左側開始。 若 Start 省略,則使用 -1,意即搜尋從最後一個字元位置開始。 搜尋從右向左進行。
- Compare
- CompareMethod
Optional. 數值表示在評估子字串時應使用的比較類型。 若省略,則進行二元比較。 數值請參見設定。
傳回
| 如果 | InStrRev 傳回 |
|---|---|
StringCheck 是零長度 | 0 |
StringMatch 是零長度 |
Start
|
StringMatch 未被發現 | 0 |
StringMatch 發現於 StringCheck | 第一個匹配點的位置,從弦的右側開始。 |
Start 長度大於 StringMatch | 0 |
例外狀況
Start = 0 或 Start< -1。
範例
此範例展示了該函數的 InStrRev 使用。
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 |
進行文本比較。 |
適用於
另請參閱
- InStr
弦在Visual Basic - Visual Basic 中的字串簡介