VBScript
InStrRev
function
The VBScript InStrRev function returns the position where one string appears in another string, starting at the end of the string.
Complete VBScript reference manual
The InStrRev function returns where the string first appears in another string.
The search starts at the end of the string, but the returned position starts at the beginning of the string.
The InStrRev function returns the following value:
-
If string1 is "" - InStrRev returns 0
-
If string1 is Null - InStrRev returns Null
-
If string2 is "" - InStrRev returns start
-
If string2 is Null - InStrRev returns Null
-
If string2 is not found - InStrRev returns 0
-
If string2 - InStrRev is found in string1, return the location where the matching string was found
-
If start sgt; Len (string1) - InStrRev returns 0
Tip: See
The InStr function.
Grammar
InStrRev(string1,string2[,start[,compare]])
parameter
|
describe
|
string1
|
Required.A string that needs to be searched.
|
string2
|
Required.String expressions that need to be searched.
|
start
|
Optional.Specifies the starting position of each search.The default search start position is the last character (-1).
|
compare
|
Optional.The string comparison type to use is specified.The default is 0.
The following values can be used:
-
0 = VBBINARYCOMPARE - Performing binary comparison
-
1 = vbtextcompare - Perform text comparison
|
Instance 1
<script type="text/vbscript">
txt="This is a beautiful day!"
document.write(InStrRev(txt,"beautiful"))
</script>
The above example output results:
11
Try it out . . .
Instance 2
Look for the letter "i" with a different starting 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>
The above example output results:
16
6
Try it out . . .
Instance 3
Look for the letter "T" with text and binary comparisons:
<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>
The above example output results:
15
1
Try it out . . .
Complete VBScript reference manual