byteOffsetFromCharacterIndex

byteOffsetFromCharacterIndex(index: Integer): Integer;

The byteOffsetFromCharacterIndex method of the StringUtf8 primitive type returns the byte offset for the character specified by the index parameter within the receiving UTF8 string.

In the following code example, the first character of the UTF8 string str8 requires two bytes with the remaining four characters requiring one byte each. The second character therefore starts at offset three (3).

vars
    str8 : StringUtf8;
begin
    str8 := @"©2007";
    write str8.byteOffsetFromCharacterIndex(1);     // writes 1
    write str8.byteOffsetFromCharacterIndex(2);     // writes 3
    write str8.byteOffsetFromCharacterIndex(3);     // writes 4
    write str8.byteOffsetFromCharacterIndex(4);     // writes 5
    write str8.byteOffsetFromCharacterIndex(5);     // writes 6
end;