posUsingByteOffset

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

The posUsingByteOffset method of the StringUtf8 primitive type returns an integer containing the byte offset of the start of a UTF8 substring within the receiver. The substring is specified by the substr parameter.

The search for the substring begins at the byte offset specified by the start parameter.

The start parameter must be greater than zero (0) and less than or equal to the number of bytes in the receiver. If the substr or the start parameter is greater than the number of bytes in 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.

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

vars
    str8 : StringUtf8;
begin
    str8 := @"۩";
    write str8.posUsingByteOffset(@"©", 3);      // Outputs 4
end;