Searching for a pattern in a stringΒΆ

instr()

Search for a pattern in a string


SYNTAX

instr(source, startpos, pattern)

Search for a text string within a longer string.

source

The source string.

startpos

Searching begins at this character of the source string, where the first character is number 1.

pattern

The string to be searched for.

The instr function returns 0 if the pattern string is not found. Otherwise it returns an integer in the range 1-255 indicating the starting position in source where the match was found.


NOTES

  • Case is significant.

  • If the length of pattern is greater than the length of source, the function always returns 0.

  • Trailing spaces are removed from pattern for the purposes of the search.


EXAMPLES

  1. This example will return 8:

    tmp.Field = "Sample Text"
    tmp.Search = "Text"
    tmp.Location = instr(tmp.Field, 1, tmp.Search)
    
  2. String not found due to position of search start - returns 0:

    tmp.Field = "AaBbCcDdEeFf"
    tmp.Search  = "Bb"
    tmp.Location = instr(tmp.Field, 5, tmp.Search)
    

RELATED TOPICS

String handling functions