VBScript InStrRev Function


Advertisements

InStrRev

The InStrRev Function returns the first occurrence of one string within another string. The Search happens from right to Left.

Syntax

InStrRev(string1,string2[,start,[compare]])

Description

  • String1, a Required Parameter. String to be searched.

  • String2, a Required Parameter. String against which String1 is searched.

  • Start, an Optional Parameter. Specifies the Starting position for the search. The Search begins at the first position from right to left.

  • Compare, an Optional Parameter. Specifies the String Comparison to be used. It can take the below mentioned values −

    • 0 = vbBinaryCompare - Performs Binary Comparison(Default)

    • 1 = vbTextCompare - Performs Text Comparison

Example

<!DOCTYPE html>
<html>
   <body>
      <script language = "vbscript" type = "text/vbscript">
         var = "Microsoft VBScript"
         document.write("Line 1 : " & InStrRev(var,"s",10) & "<br />")
         document.write("Line 2 : " & InStrRev(var,"s",7) & "<br />")
         document.write("Line 3 : " & InStrRev(var,"f",-1,1) & "<br />")
         document.write("Line 4 : " & InStrRev(var,"t",5) & "<br />")
         document.write("Line 5 : " & InStrRev(var,"i",7) & "<br />")
         document.write("Line 6 : " & InStrRev(var,"i",7) & "<br />")
         document.write("Line 7 : " & InStrRev(var,"VB",1))
      </script>
   </body>
</html>

When you save it as .html and execute it in Internet Explorer, then the above script will produce the following result −

Line 1 : 6
Line 2 : 6
Line 3 : 8
Line 4 : 0
Line 5 : 2
Line 6 : 2
Line 7 : 0 
vbscript_strings.htm
Advertisements