返回某字符串在另一個字符串中出現(xiàn)的從結(jié)尾計起的位置。
InStrRev(string1, string2[, start[, compare]])
string1
必選項。接受搜索的字符串表達式。
string2
必選項。被搜索的字符串表達式。
Start
可選項。數(shù)值表達式,用于設(shè)置每次搜索的開始位置。如果省略,則默認值為 -1,表示從最后一個字符的位置開始搜索。如果 start 包含 Null,則出現(xiàn)錯誤
compare
可選項。在計算子字符串時,指示要使用的比較類型的數(shù)值。如果省略,將執(zhí)行二進制比較。有關(guān)數(shù)值,請參閱“設(shè)置”部分。
compare 參數(shù)可以有以下值:
| 常數(shù) | Value | 描述 | 
|---|---|---|
| vbBinaryCompare | 0 | 執(zhí)行二進制比較。 | 
| vbDatabaseCompare | 2 | 執(zhí)行基于包含在數(shù)據(jù)庫(在此數(shù)據(jù)庫中執(zhí)行比較)中的信息的比較。 | 
InStrRev 返回以下值:
| 如果 | InStrRev 返回 | 
|---|---|
| string1 為零長度 | 0 | 
| string1 為 Null | Null | 
| string2 為零長度 | start | 
| string2 為 Null | Null | 
| string2 沒有找到 | 0 | 
| 在 string1 中找到 string2 | 找到匹配字符串的位置 | 
| start > Len(string2) | 0 | 
下面的示例利用 InStrRev 函數(shù)搜索字符串:
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 函數(shù)的語法與 InStr 函數(shù)的語法并不一樣。
新聞熱點
疑難解答
圖片精選