InStrRev Function

   
InStrRev Function

Class

Microsoft.VisualBasic.Strings

Syntax

 InstrRev(   stringcheck, stringmatch   [,   start   [,   compare   ]]) 
stringcheck (required; String)

The string to be searched.

stringmatch (required; String)

The substring to be found within stringcheck .

start (optional; Numeric)

The starting position of the search. If no value is specified, start defaults to 1.

compare (optional; CompareMethod enumeration)

A constant indicating how stringcheck and stringmatch should be compared.

Return Value

Long

Description

Determines the starting position of a substring within a string by searching from the end of the string to its beginning

Rules at a Glance

  • While InStr searches a string from left to right, InStrRev searches a string from right to left.

  • The compare argument can be one of CompareMethod.Binary (for a case- sensitive search) or CompareMethod.Text (for a case-insensitive search). If compare is omitted, the type of comparison is binary. Note that Option Compare is not used, unlike with the InStr function.

  • start designates the starting point of the search as counted from the start of stringcheck . To start the search at the end of stringcheck , either omit the start argument or set it to -1.

  • If stringmatch is not found, InStrRev returns 0.

  • If stringmatch is found within stringcheck , the value returned by InStrRev is the position of stringcheck from the start of the string.

Example

This example uses both InStr and InStrRev to highlight the different results produced by each. Using a stringcheck of "I like the functionality that InStrRev gives", InStr finds the first occurrence of "th" at character 8, while InStrRev finds the first occurrence of "th" at character 26.

 Dim myString, sSearch As String myString = "I like the functionality that InsStrRev gives" sSearch = "th" Console.WriteLine(InStr(myString, sSearch))     Console.WriteLine(InStrRev(myString, sSearch)) 

See Also

InStr Function

   


VB.Net Language in a Nutshell
VB.NET Language in a Nutshell
ISBN: B00006L54Q
EAN: N/A
Year: 2002
Pages: 503

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net