-
InstrRev
鎖定
InStrRev是一個 函數,可返回一個字符串(1)在另一個字符串(2)中左起最後一次出現的位置。默認檢索整個字符串(2),也可以用參數限定檢索字符的數量。
- 外文名
- InstrRev
- 開始位置
- 從字符串的末端
- 返回的位置
- 字符串的起點開始
- 相似函數
- InStr
InstrRev描述
語法
InstrRev(string1, string2[, start[, compare]])
InstrRev 函數的語法有以下參數:
參數
string1
必選項。接受搜索的字符串表達式。
string2
必選項。被搜索的字符串表達式。
Start
可選項。數值表達式,用於設置每次搜索的開始位置。如果省略,則默認值為 -1,表示從最後一個字符的位置開始搜索。如果 start 包含 Null,則出現錯誤。是指從左起第n個字符起,從右向左開始數遇到的第一個匹配的字符(串),在string1中左起第幾個字符。這個函數的思路(雙重否定)和參數的名稱(Start)都有點繞,容易誤解成倒數第幾個字符。如果把這個參數理解為Length就能理順很多,即:在String1的前n個字符中,String2最後一次出現的位置。
compare
可選項。在計算子字符串時,指示要使用的比較類型的數值。如果省略,將執行二進制比較。有關數值,請參閲“設置”部分。
InstrRev設置
compare 參數可以有以下值:
常數 | 描述 | |
vbBinaryCompare | 0 | 執行二進制比較。 |
vbTextCompare | 1 | 執行文本比較。 |
vbDatabaseCompare | 2 | 執行基於包含在數據庫(在此數據庫中執行比較)中的信息的比較。 |
InstrRev返回值
InStrRev 返回以下值:
如果 | InStrRev 返回 |
string1 為零長度 | 0 |
string1 為 Null | Null |
string2 為零長度 | start |
string2 為 Null | Null |
string2 沒有找到 | 0 |
在 string1 中找到 string2 | 找到匹配字符串的位置 |
start > Len(string1) | 0 |
説明
下面的示例利用 InStrRev 函數搜索字符串:
Dim SearchString, SearchChar, MyPos
SearchString ="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 函數的語法並不一樣。
要求 版本 2
請參閲 Instr 函數
- 詞條統計
-
- 瀏覽次數:次
- 編輯次數:15次歷史版本
- 最近更新: oalz