scanWhile

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

The scanWhile method of the String primitive type returns a 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
    i: Integer;
    s: String;
begin
    i:= 3;
    s:= '0246'.scanWhile('0123456789', i);
    write '<' & s & '> ' & i.String;       // 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
    stringValue : String;
    pos         : Integer;
begin
    stringValue := "this:is/a;string";
    pos := 1;
    write stringValue.scanWhile("abcdefghijklmnopqrstuvwxyz", pos);
    // Outputs this
    pos := pos+1;
    write stringValue.scanWhile("abcdefghijklmnopqrstuvwxyz", pos);
    // Outputs is
end;

See also the String primitive type scanUntil method.