substringAtByteOffset

substringAtByteOffset(offset: Integer;
                      length: Integer): StringUtf8;

The substringAtByteOffset method of the StringUtf8 primitive type returns a UTF8 substring beginning with the character that starts at the byte offset specified by the value of the offset parameter within the receiving UTF8 string or after that offset; that is, the method scans from the offset position forwards to find the next character.

The value of the length parameter determines the maximum number of characters that can be returned in the UTF8 substring.

In the following code example, the first character of the string str8 requires three bytes for UTF8 encoding. The first character starts at byte offset one (1) and the second character at byte offset four (4).

vars
    str8: StringUtf8;
begin
    str8 := @"€xyz";
    write str8.substringAtByteOffset(3,2);   // writes xy
end;