InStrRev - VBScript


InStrRev locates a substring within a string, starting from the end of the string and moving backward.


Namespace: Microsoft.VisualBasic

Public Function InStrRev(ByVal String1 As String, ByVal String2 As String [, ByVal Start As Integer]) As Integer


| Option | Description | Default |
| Start | The starting position from the end of String1. | 0 (start at the end of the string) |


' Find the last occurrence of "VB" within "VBNET"
Dim lastOccurrence As Integer = InStrRev("VBNET", "VB")
Console.WriteLine("Last occurrence of ""VB"": " & lastOccurrence)
' Find the last occurrence of "VBA" within "VB" starting from the 3rd character from the end of the string
Dim lastOccurrence As Integer = InStrRev("VB", "VBA", 3)
Console.WriteLine("Last occurrence of ""VBA"": " & lastOccurrence)

Common Issues

  • Make sure both String1 and String2 are not empty strings.
  • If Start is negative or greater than the length of String1, an error will occur.


InStrRev can be used in conjunction with other string manipulation functions, such as Replace() and Split(), to perform more complex string operations.

  • InStr()
  • LCase()
  • StrLen()