From Xojo Documentation
|You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!|
| This item was deprecated in version 2019r2.
Please use String.IndexOf as a replacement.
Note that InStr is 1-based and IndexOf is 0-based.
result = InStr([start,] source, find)
result = stringVariable.InStr([start,] find)
|result||Integer||The position of the first occurrence of find in source. If the search string cannot be located in source, InStr returns 0.|
|start||Integer||Optional one-based position from which to begin searching the source string. The default is 0.|
|source||String||Required. String expression being searched.|
|find||String||Required. String expression being sought.|
|stringVariable||String||Any variable of type String.|
If the find string is not found within the source string, 0 (zero) is returned. If the find string is an empty string, then start is returned. That is, InStr("This", "") returns 0 and InStr(3, "This","") returns 3.
InStr is case-insensitive, even with accented Roman characters and non-Roman alphabets.
If you need to find the byte position of the find string within the source string or need a case-sensitive function, use the InStrB function.
This example uses the InStr function to locate a string within another string.
first = InStr("This is a test", "t") // returns 1
first = InStr("This is a test", "is") // returns 3
first = InStr(4, "This is a test", "is") // returns 6
first = InStr("This is a test", "tester") // returns 0
Dim s As String
s = "This is a test"
first = s.InStr("test") // returns 11