InStr

From Xojo Documentation
Jump to: navigation, search
Method

Returns the position of the first occurrence of a string inside another string. The first character is numbered 1.

Syntax

result = InStr([start,] source, find)
OR
result = stringVariable.InStr([start,] find)

Part Type Description
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.

Notes

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.

Examples

This example uses the InStr function to locate a string within another string.

Dim first As Integer
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

See Also

Asc, Chr, InStrB, Left, Len, Mid, NthField, Right, Split, StrComp functions.

Personal tools
Namespaces

Variants
Actions
Main
Content
Starting Out
Dig Deeper
More Help
Toolbox
About