Name
InStr Function
Class
Microsoft.VisualBasic.Strings
Syntax
InStr(start, string1, string2[, compare])or:
InStr(string1, string2[, compare])-
start Use: Required in first syntax
Data Type: Numeric
The starting position for the search
-
string1 Use: Required
Data Type: String
The string being searched
-
string2 Use: Required
Data Type: String
The string being sought
-
compare Use: Optional
Data Type:
CompareMethodenumerationThe 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
InStris influenced by the values ofstring1andstring2, as the following table details:Condition
InStr return value
string1is zero-length orNothing0
string2is zero-length orNothingstartstring2not found0
string2found withinstring1Position at which the start of
string2is foundstart > len(string2)0
In the second syntax,
InStrcommences the search with the first character ofstring1.If the
startargument is 0 orNothing, an error occurs.The
compareargument can be one ofCompareMethod.Binary(a case-sensitive comparison) orCompareMethod.Text(a case-insensitive comparison). Ifcomparemodeis omitted, the type of comparison is determined by theOptionComparesetting.
See Also
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