Examples

Dim SearchString, SearchChar, MyPos
SearchString =”XXpXXpXXPXXP”  ‘ String to search in.
SearchChar = “P”  ‘ Search for “P”.
MyPos = InStr(4, SearchString, SearchChar, 1)  ‘ A textual comparison starting at position 4. Returns 6.
MyPos = InStr(1, SearchString, SearchChar, 0)  ‘ A binary comparison starting at position 1. Returns 9.
MyPos = InStr(SearchString, SearchCharb  ‘ Comparison is binary by default (last argument is omitted). Returns 9.
MyPos = InStr(1, SearchString, “W”)  ‘ A binary comparison starting at position 1. Returns 0 (“W” is not found).
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:

The InStrB function, used with byte data that is contained in strings, returns byte position, rather than character position.

Note:

The syntax for the InStrRev function differs from the syntax for the InStr function.