| InStr, InStrB Functions |
Named Arguments
No
Syntax
InStr([start, ]stringtosearch, stringtofind[, _
comparemode])
start
Use: Optional
Data Type: Numeric
The starting position for the search.
stringtosearch
Use: Required
Data Type: String
The string being searched.
stringtofind
Use: Required
Data Type: String
The string being sought.
comparemode
Use: Optional
Data Type: Integer
The type of string comparison.
Return Value
A variant of subtype Long.
Description
Finds the starting position of one string within another.
Rules at a Glance
The return value of InStr is influenced by the values of stringtosearch and stringtofind, as the following table details:
Condition InStr Return Value stringtosearch is zero-length 0 stringtosearch is Null Null stringtofind is zero-length start stringtofind is Null Null stringtofind is not found 0 stringtofind found within stringtosearch Position at which the start of stringtofind is found start > len(stringtofind) 0 If the start argument is omitted, InStr commences the search with the first character of stringtosearch.
If the start argument is Null, an error occurs.
You must specify a start argument if you are specifying a comparemode argument.
VB5 and VBA support intrinsic constants for comparemode, as follows:
Comparison Mode Value Constant Binary (default) 0 vbBinaryCompare Text—case insensitive 1 vbTextCompare Database (Microsoft Access only) 2 vbDatabaseCompare If the comparemode argument contains Null, an error is generated.
If comparemode is ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access