InStrRev function
Returns the position from the end of a string that appears in another string.
InStrRev(string1, string2[, start[, compare]])
Parameters
String1
Required option. The string expression that accepts the search.
string2
Required option. The string expression being searched for.
Start
Options available. A numeric expression that sets the starting position for each search. If omitted, the default value is-1, which indicates that the search begins at the last character position. If start contains Null, an error occurs
Compare
Options available. Indicates the numeric value of the comparison type to use when calculating the substring. If omitted, a binary comparison is performed. For numeric values, see the "Settings" section.
Set up
The compare parameter can have the following values:
| Constants |
Value |
Description |
| Vbbinarycompare |
0 |
Performs a binary comparison. |
| Vbdatabasecompare |
2 |
Execution is based on a comparison of the information contained in the database (performing comparisons in this database). |
return value
InStrRev returns the following values:
| if |
InStrRev return |
| String1 is zero length |
0 |
| String1 is Null |
Null |
| string2 is zero length |
Start |
| String2 is Null |
Null |
| String2 didn't find it. |
0 |
| Find string2 in string1. |
Find the location of the matching string |
| Start > Len (string2) |
0 |
Description
The following example uses the InStrRev function to search for a string:
Dim SearchString, SearchChar, MyPosSearchString ="XXpXXpXXPXXP" ' String to search in.SearchChar = "P" ' Search for "P".MyPos = InstrRev(SearchString, SearchChar, 10, 0)' A binary comparison starting at position 10. Returns 9.MyPos = InstrRev(SearchString, SearchChar, -1, 1)' A textual comparison starting at the last position. Returns 12.MyPos = InstrRev(SearchString, SearchChar, 8)' Comparison is binary by default (last argument is omitted). Returns 0.
Note that the syntax of the InStrRev function is not the same as the syntax of the InStr function.