Product SiteDocumentation Site

7.4.46. POS (Position)


>>-POS(needle,haystack--+---------------------------+--)--------------------------><
                        +-,--+-------+--+---------+-+
                             +-start-+  +-,length-+

Returns the position of one string, needle, in another, haystack. (See also Section 7.4.36, “LASTPOS (Last Position)”.) It returns 0 if needle is a null string or not found or if start is greater than the length of haystack. By default, the search starts at the first character of the receiving string (that is, the value of start is 1), and continues to the end of the string. You can override this by specifying start , the point at which the search starts, and length, the bounding limit for the search. If specified, start must be a positive whole number and length must be a non-negative whole number.
Here are some examples:

Example 7.60. Builtin function POS

POS("day","Saturday")       ->    6
POS("x","abc def ghi")      ->    0
POS(" ","abc def ghi")      ->    4
POS(" ","abc def ghi",5)    ->    8
POS(" ","abc def ghi",5,3)  ->    0