4.05 String Searching

Instr

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

Syntax:

instr(s1, s2[, start])

where:

s1
The haystack.
s2
The needle.
start
The starting position.


Returns:

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

If there is no match, instr returns 0

Description:

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.

Example:

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.

Notes:

  • 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)