VBScript InStrRev 函數

InStrRev 函數返回字串在另一字串中首次出現的位置。搜索從字串的末端開始,但是返回的位置是從字串的起點開始計數的。
InStrRev 函數可返回下麵的值:
- 如果 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 函數。
語法
InStrRev(string1,string2[,start[,compare]])
參數 | 描述 |
---|---|
string1 | 必需。需要被搜索的字串。 |
string2 | 必需。需要搜索的字串運算式。 |
start | 可選。規定每次搜索的起始位置。默認的搜索起始位置是最後一個字元(-1)。 |
compare | 可選。規定要使用的字串比較類型。默認是 0。 可採用下列的值:
|
實例
實例 1
<script type="text/vbscript">
txt="This is a beautiful day!"
document.write(InStrRev(txt,"beautiful"))
</script>
txt="This is a beautiful day!"
document.write(InStrRev(txt,"beautiful"))
</script>
以上實例輸出結果:
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>
txt="This is a beautiful day!"
document.write(InStrRev(txt,"i",-1) & "<br />")
document.write(InStrRev(txt,"i",7) & "<br />")
</script>
以上實例輸出結果:
16
6
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>
txt="This is a beautiful day!"
document.write(InStrRev(txt,"T",-1,1) & "<br />")
document.write(InStrRev(txt,"T",-1,0) & "<br />")
</script>
以上實例輸出結果:
15
1
1
