Purpose
Returns the position of the first occurrence of one string (the search string) within another (the source string).
If the search string is found within the source string, this function returns an integer that indicates the character position of the first occurrence of the string.
If the search string is not found, InStr returns 0.
If the search string is a zero-length string, the start value is returned.
Syntax
InStr ([Start,] SourceString, SearchString [Case])
Start |
Must be used if you use Case. A valid numeric expression used to offset the starting position of the search in SourceString. If the Start argument is omitted, the default starting offset is 1. |
Case |
Determines the case sensitivity of the comparison. If Case is 0, the comparison is case sensitive (example: "a"<>"A"). If Case is 1, the comparison is case insensitive (example: "a"="A"). If the Case argument is omitted, the default behavior is case sensitive comparisons. |
Example
Sub Main()
Dim s As String, Ioc As Integer
s = "the quick brown fox jumps over the lazy dog"
Ioc = InStr(s, "fox")
If Ioc<>0 Then
Print "The string 'fox' was first found at character position "; Ioc
Else
Print "The string 'fox' was not found in the search string"
End If
End Sub
|