VBScript InStrRev function
InStrRev function returns the position of the first occurrence of a string in another string. Start searching from the end of the string, but the return position from the beginning of the string counted.
InStrRev function can return the following values:
- If string1 is "" - InStrRev returns 0
- If string1 is Null - Null InStrRev return
- If string2 is "" - InStrRev return to start
- If string2 is Null - Null InStrRev return
- If string2 is not found - InStrRev returns 0
- If string2 is found within string1 in - InStrRev return to find the matching string location
- If start> Len (string1) - InStrRev returns 0
Tip: See the InStr function.
grammar
InStrRev(string1,string2[,start[,compare]])
参数 | 描述 |
---|---|
string1 | 必需。需要被搜索的字符串。 |
string2 | 必需。需要搜索的字符串表达式。 |
start | 可选。规定每次搜索的起始位置。默认的搜索起始位置是最后一个字符(-1)。 |
compare | 可选。规定要使用的字符串比较类型。默认是 0。 可采用下列的值:
|
Examples
Example 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>
Examples of the above output:
11
try it"
Example 2
Find the letter "i", with different start position:
<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>
Examples of the above output:
16
6
6
try it"
Example 3
Find the letter "T", using both text and binary comparison:
<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>
Examples of the above output:
15
1
1
try it"
Complete VBScript Reference