Appearance
Pos
Pos returns the position of the first occurrence of Pattern in string S.
The first position in S is 1, the second position in S is 2 e.t.c.
By default, the search for Pattern starts at position 1 in the string S,
Pattern can have any number of characters.
Pos will return zero (0) -
- If Pattern is not found.
- If either Pattern or S is an empty string with a length of zero (0).
- If Pattern is longer than S.
Pos is case-sensitive so the characters are matched exactly.
Please also refer to the function PosEx which performs a similar function, but allows you to offset the starting search position.
Declaration: function Pos( const Pattern, S : string) : integer;
Several examples follow.
pascal
procedure OnMapEvent(var Value:Variant);
begin
Value := Pos('-','ab-cde-fgh'); //returns 3
Value := Pos('00', '12-1234-0012345-00'); // returns 9
Value := Pos('xx', 'abcdef'); // returns 0
Value := Pos('x', ''); // returns 0
Value := Pos('', 'xxx'); // returns 0
Value := Pos('a', 'AAA'); // returns 0
end;
