<div class="meta" robots="noindex">

</div>

Method

# InStr

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<div class="warning">

<div class="title">

Warning

</div>

This item was deprecated in version 2019r2. Please use `String.IndexOf<string.indexof>` as a replacement.

</div>

## Description

Returns the position of the first occurrence of a `string</api/data_types/string>` inside another `string</api/data_types/string>`. The first character is numbered 1.

## Usage

*result* = **InStr**(\[*start*,\] *source*, *find*)

**OR**

*result* = *stringVariable*.**InStr**(\[*start*,\] *find*)

| Part           | Type                               | Description                                                                                                                    |
|----------------|------------------------------------|--------------------------------------------------------------------------------------------------------------------------------|
| result         | `Integer</api/data_types/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</api/data_types/integer>` | Optional one-based position from which to begin searching the source string. The default is 0.                                 |
| source         | `String</api/data_types/string>`   | Required. `String</api/data_types/string>` expression being searched.                                                          |
| find           | `String</api/data_types/string>`   | Required. `String</api/data_types/string>` expression being sought.                                                            |
| stringVariable | `String</api/data_types/string>`   | Any variable of type `String</api/data_types/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, <span class="title-ref">InStr</span>("This", "") returns 0 and <span class="title-ref">InStr</span>(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 `String.IndexOfBytes<string.indexofbytes>` function.

## Sample code

This example uses the <span class="title-ref">InStr</span> function to locate a string within another string.

``` xojo
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
```

## Compatibility

All project types on all supported operating systems.

## See also

`Asc</api/math/asc>`, `Chr</api/text/chr>`, `String.IndexOfBytes<string.indexofbytes>`, `String.Left<string.left>`, `String.Length<string.length>`, `String.Middle<string.middle>`, `String.NthField<string.nthfield>`, `String.Right<string.right>`, `String.Split<string.split>`, `String.Compare<string.compare>` functions.
