Name
InStr, InStrB Functions
Syntax
InStr([start, ]stringtosearch,stringtofind[,comparemode])
-
start Use: Optional
Data Subtype: Numeric
The starting position for the search.
-
stringtosearch Use: Required
Data Subtype: String
The string being searched.
-
stringtofind Use: Required
Data Subtype: String
The string being sought.
-
comparemode Use: Optional
Data Subtype: 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
InStris influenced by the values ofstringtosearchandstringtofind, as shown in the following table:Condition
InStr Return Value
stringtosearchis zero-length0
stringtosearchisNullNullstringtofindis zero-lengthstartstringtofindisNullNullstringtofindis not found0
stringtofindis found withinstringtosearchPosition at which the start of
stringtofindis foundstart>len(stringtofind)0
If the
startargument is omitted, InStr commences the search with the first character ofstringtosearch.If the
startargument isNull, an error occurs.You must specify a
startargument if you are specifying acomparemodeargument.VBScript supports intrinsic constants for
comparemode, as follows:Comparison Mode
Value
Constant
Binary (default)
0
vbBinaryCompareText—case insensitive
1
vbTextCompareIn effect, a binary comparison means that the search for
stringtofindinstringtosearchis case-sensitive. A text ...
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