Instr

String management function.

The Instr function returns the position of one string within another.

Usage

Mainly used to extract a substring from one string. For example, Instr function can be used to extract only the filename from a long filename including the path, or only the filename without the extension. See the script example Extract name, directory and extension from a full filename.

Syntax

pos=Instr(<target_string>,<search_string>)

Parameters

<target_string>, string to be searched

<search_string>, string to search for

Return value

Pos returns the position where the search string was found. If the search string is not found in the target string, 0 is returned; if <target_string> or <search_string> are empty, 0 is also returned.

See also

InstrRev

Extract the first and second word from a string

Extract name, directory and extension from a full filename

ExtractBetween$

Examples

 

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

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