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
InStr
is influenced by the values ofstringtosearch
andstringtofind
, as shown in the following table:Condition
InStr Return Value
stringtosearch
is zero-length0
stringtosearch
isNull
Null
stringtofind
is zero-lengthstart
stringtofind
isNull
Null
stringtofind
is not found0
stringtofind
is found withinstringtosearch
Position at which the start of
stringtofind
is foundstart
>
len(stringtofind)
0
If the
start
argument is omitted, InStr commences the search with the first character ofstringtosearch
.If the
start
argument isNull
, an error occurs.You must specify a
start
argument if you are specifying acomparemode
argument.VBScript supports intrinsic constants for
comparemode
, as follows:Comparison Mode
Value
Constant
Binary (default)
0
vbBinaryCompare
Text—case insensitive
1
vbTextCompare
In effect, a binary comparison means that the search for
stringtofind
instringtosearch
is case-sensitive. A text ...
Get VBScript in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.