返回某字符串在另一個字符串中出現的從結尾計起的位置。
InStrRev(string1, string2[, start[, compare]])
string1
必選項。接受搜索的字符串表達式。
string2
必選項。被搜索的字符串表達式。
Start
可選項。數值表達式,用于設置每次搜索的開始位置。如果省略,則默認值為 -1,表示從最后一個字符的位置開始搜索。如果 start 包含 Null,則出現錯誤
compare
可選項。在計算子字符串時,指示要使用的比較類型的數值。如果省略,將執行二進制比較。有關數值,請參閱“設置”部分。
compare 參數可以有以下值:
| 常數 | Value | 描述 |
|---|---|---|
| vbBinaryCompare | 0 | 執行二進制比較。 |
| vbDatabaseCompare | 2 | 執行基于包含在數據庫(在此數據庫中執行比較)中的信息的比較。 |
InStrRev 返回以下值:
| 如果 | InStrRev 返回 |
|---|---|
| string1 為零長度 | 0 |
| string1 為 Null | Null |
| string2 為零長度 | start |
| string2 為 Null | Null |
| string2 沒有找到 | 0 |
| 在 string1 中找到 string2 | 找到匹配字符串的位置 |
| start > Len(string2) | 0 |
下面的示例利用 InStrRev 函數搜索字符串:
Dim SearchString, SearchChar, MyPosSearchString ="XXpXXpXXPXXP" ' String to search in.SearchChar = "P" ' Search for "P".MyPos = InstrRev(SearchString, SearchChar, 10, 0)' A binary comparison starting at position 10. Returns 9.MyPos = InstrRev(SearchString, SearchChar, -1, 1)' A textual comparison starting at the last position. Returns 12.MyPos = InstrRev(SearchString, SearchChar, 8)' Comparison is binary by default (last argument is omitted). Returns 0.
注意 InStrRev 函數的語法與 InStr 函數的語法并不一樣。
新聞熱點
疑難解答