VBScript InStrRev 函數(shù)
完整的 VBScript 參考手冊
InStrRev 函數(shù)返回字符串在另一字符串中首次出現(xiàn)的位置。搜索從字符串的末端開始,但是返回的位置是從字符串的起點開始計數(shù)的。
InStrRev 函數(shù)可返回下面的值:
- 如果 string1 為 "" - InStrRev 返回 0
- 如果 string1 為 Null - InStrRev 返回 Null
- 如果 string2 為 "" - InStrRev 返回 start
- 如果 string2 為 Null - InStrRev 返回 Null
- 如果 string2 沒有找到 - InStrRev 返回 0
- 如果在 string1 中找到 string2 - InStrRev 返回找到匹配字符串的位置
- 如果 start > Len(string1) - InStrRev 返回 0
提示:請參閱 InStr 函數(shù)。
語法
InStrRev(string1,string2[,start[,compare]])
參數(shù) | 描述 |
string1 | 必需。需要被搜索的字符串。 |
string2 | 必需。需要搜索的字符串表達式。 |
start | 可選。規(guī)定每次搜索的起始位置。默認的搜索起始位置是最后一個字符(-1)。 |
compare | 可選。規(guī)定要使用的字符串比較類型。默認是 0。 可采用下列的值: - 0 = vbBinaryCompare - 執(zhí)行二進制比較
- 1 = vbTextCompare - 執(zhí)行文本比較
|
實例
實例 1
<script type="text/vbscript">
txt="This is a beautiful day!"
document.write(InStrRev(txt,"beautiful"))
</script>
以上實例輸出結(jié)果:
11
嘗試一下 ? 實例 2
查找字母 "i",采用不同的起始位置:
<script type="text/vbscript">
txt="This is a beautiful day!"
document.write(InStrRev(txt,"i",-1) & "<br />")
document.write(InStrRev(txt,"i",7) & "<br />")
</script>
以上實例輸出結(jié)果:
16
6
嘗試一下 ? 實例 3
查找字母 "T",采用文本和二進制比較:
<script type="text/vbscript">
txt="This is a beautiful day!"
document.write(InStrRev(txt,"T",-1,1) & "<br />")
document.write(InStrRev(txt,"T",-1,0) & "<br />")
</script>
以上實例輸出結(jié)果:
15
1
嘗試一下 ?
完整的 VBScript 參考手冊