InStrRev Function (Visual Basic)

Returns the position of the first occurrence of one string within another, starting from the right side of the string.

Public Function InStrRev(
   ByVal StringCheck As String,
   ByVal StringMatch As String,
   Optional ByVal Start As Integer = -1,
   Optional ByVal Compare As CompareMethod = CompareMethod.Binary
) As Integer

Parameters

  • StringCheck
    Required. String expression being searched.

  • StringMatch
    Required. String expression being searched for.

  • Start
    Optional. Numeric expression setting the one-based starting position for each search, starting from the left side of the string. If Start is omitted then –1 is used, meaning the search begins at the last character position. Search then proceeds from right to left.

  • Compare
    Optional. Numeric value indicating the kind of comparison to use when evaluating substrings. If omitted, a binary comparison is performed. See Settings for values.

Settings

The Compare argument can have the following values.

Constant

Description

Binary

Performs a binary comparison.

Text

Performs a textual comparison.

Return Value

InStrRev returns the following values.

If

InStrRev returns

StringCheck is zero-length

0

StringMatch is zero-length

Start

StringMatch is not found

0

StringMatch is found within StringCheck

Position at which the first match is found, starting with the right side of the string.

Start is greater than length of StringMatch

0

Exceptions

Exception type

Error number

Condition

ArgumentException

5

Start = 0 or Start < -1.

See the "Error number" column if you are upgrading Visual Basic 6.0 applications that use unstructured error handling. (You can compare the error number against the Number Property (Err Object).) However, when possible, you should consider replacing such error control with Structured Exception Handling Overview for Visual Basic.

Remarks

Note that the syntax for the InStrRev function is not the same as the syntax for the InStr function.

Example

This example demonstrates the use of the InStrRev function.

Dim TestString As String = "the quick brown fox jumps over the lazy dog" 
Dim TestNumber As Integer 
' Returns 32.
TestNumber = InStrRev(TestString, "the")
' Returns 1.
TestNumber = InStrRev(TestString, "the", 16)

Requirements

Namespace:Microsoft.VisualBasic

**Module:**Strings

Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)

See Also

Reference

InStr Function (Visual Basic)

Other Resources

Strings in Visual Basic

Introduction to Strings in Visual Basic