pos

pos(substr: StringUtf8;
    start:  Integer): Integer;

The pos method of the StringUtf8 primitive type returns an integer containing the character index of the start of a substring within a string. The substring is specified by the substr parameter. The search for the substring begins at the character index specified by the start parameter.

The start parameter must be greater than zero (0) and less than or equal to the length of the receiver. If the substr or the start parameter is greater than the length of the receiver, this method returns zero (0).

This method returns zero (0) if the specified substring is not found.

The character search is case-sensitive.

The following example shows the use of the pos method.

vars
    str8 : StringUtf8;
begin
    str8 := @'position example';
    write str8.pos('pos', 1);    // Outputs 1
    write str8.pos('pos', 10);   // Outputs 0
end;