4.05 String Searching


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


instr(s1, s2[, start])


The haystack.
The needle.
The starting position.


The position of the “needle” in the “haystack”.

If there is no match, instr returns 0


Locates the position of the first occurrence of a substring or character within a string.

If start is not specified, the search begins at the first character.

If start is negative the search is carried out backwards starting at the offset from the end.

Zero (0) is returned if the substring is not found or either the str or substring are empty.

(To be implemented.) If the Any keyword is specified, InStr returns the first occurrence of any character in the substring.


put instr('abcabc','b')      // 2
put instr('abcabc','b', 3)   // 5
put instr('abcabc','b', 5)   // 5
put instr('abcabc','b', 6)   // 0
put instr('abcabc','b', -2)  // 5
put instr('abcabc','b', -5)  // 2
put instr('abcabc','b', -6)  // 0

Implementation Status

LynPlex Interpreter
Fully implemented
LynPlexC Compiler
Implemented but to be changed to above rules
Order of arguments is different. Reverse searching done by InStrRev function.
Option Any is implemented.
LynPlexS Compiler
Implemented but to be changed to above rules
Supported by four separate functions (Instr, InstrI, Rinstr, RinstrI). Two functions allow for case insensitive search.


  • Case insensitive search to be added to all versions.
  • Any option to be added to all versions.

lynplex/lp0405.txt · Last modified: 2013/06/05 10:14 (external edit)