InStr Function

Returns the position of a string within another string.

The Instr function returns the position at which the match was found. If the string was not found, the function returns 0.

Syntax:


InStr ([Start As Long,] String1 As String, String2 As String[, Compare]) As Integer

Return value:

Integer

Parameters:

Start: A numeric expression that marks the position in a string where the search for the specified substring starts. If you omit this parameter, the search starts at the first character of the string. The minimum allowed value is 1. The maximum allowed value is 2,147,483,648.

String1: The string expression that you want to search.

String2: The string expression that you want to search for.

Compare: Optional numeric expression that defines the type of comparison. The value of this parameter can be 0 or 1. The default value of 1 specifies a text comparison that is not case-sensitive. The value of 0 specifies a binary comparison that is case-sensitive.

To avoid a run-time error, do not set the Compare parameter if the first optional parameter is omitted.

Error codes:

5 Invalid procedure call

Example:


Sub ExamplePosition
Dim sInput As String
Dim iPos As Integer
    sInput = "Office"
    iPos = Instr(sInput,"c")
    Print iPos
End Sub

Please support us!