Home > Language Reference > String Management Functions > InStr

InStr

The InStr function returns the position of a string in another string.

Usage

Used to find out if one set of characters (a string) is contained in another.  

Syntax

var=InStr(<source_string>, <string_to_search>)

Parameters

<source_string>, string that will be searched.

<string_to_search>, string to search for. 

Return value

var, integer, position of the first occurrence of <string_to_search> in <source_string>. If no occurrence is found, the return value is 0.

Remarks

Use this function in an If...EndIf block to test if a text is in a string or not.

See also

Asc
Chr$
Encrypt
ExtractBetween$
InStrRev
LCase$
Left$
Len
LTrim$
Mid$
Replace$
Right$
RTrim$
SplitIntoArray
Str$
Trim$
UCase$
Val

Examples

pos = Instr("abcdefg","de") ' returns 4

pos = Instr("abcdefg","dz") ' returns 0