Name
InStr Function
Class
Microsoft.VisualBasic.Strings
Syntax
InStr(start, string1, string2
[,compare
])
or:
InStr(string1
,string2
[,compare
])
-
start
(required in first syntax; Numeric) The starting position for the search
-
string1
(required; String) The string being searched
-
string2
(required; String) The string being sought
-
compare
(optional;CompareMethod
enumeration) The type of string comparison
Return Value
An Integer indicating the position of the first occurrence of
string2
in
string1
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
string1
andstring2
, as the following table details:
Condition |
InStr return value |
---|---|
|
0 |
|
|
|
0 |
|
Position at which the start of |
|
0 |
In the second syntax, InStr commences the search with the first character of
string1
.If the
start
argument is 0 orNothing
, an error occurs.The
compare
argument can be one ofCompareMethod.Binary
(a case- sensitive comparison) orCompareMethod.Text
(a case-insensitive comparison). Ifcomparemode
is omitted, the type of comparison is determined by theOption
Compare
setting.
See Also
Get VB.NET Language in a Nutshell, Second Edition 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.