scanWhile

scanWhile(characters: StringUtf8;
          index:      Integer io): StringUtf8;

The scanWhile method of the StringUtf8 primitive type returns a UTF8 substring of the receiving string starting from the index specified in the index parameter up to (but not including) the first occurrence of any character other than the characters specified in the characters parameter.

The index of the delimiting character is specified in the second parameter. If a delimiting character is not found, the return value is the remainder of the string and an index value of zero (0) is returned in the second parameter, as shown in the following example.

vars
    index : Integer;
    str8  : StringUtf8;
begin
    index := 3;
    str8 := @'0246'.scanWhile(@'0123456789', index);
    write '<' & str8 & '> ' & index.StringUtf8;
    // outputs <46> 0, not <> 0
end;

The character search is case-sensitive.

The delimiting character is any character that is not specified in the characters parameter.

The following example shows the use of the scanWhile method.

vars
    str8  : StringUtf8;
    index : Integer;
begin
    str8 := @"this:is/a;string";
    index := 1;
    write str8.scanWhile(@"abcdefghijklmnopqrstuvwxyz", index);
    // Outputs this
    index := index + 1;
    write str8.scanWhile(@"abcdefghijklmnopqrstuvwxyz", index);
    // Outputs is
end;