UTF8Length function
Gets the length of a UTF-8-encoded string in codepoints.
Declaration
function UTF8Length(const s: string): PtrIntDescription
UTF8Length is a function used to get the character length for the
specified UTF-8-encoded string. The return value contains the number of
UTF-8-encoded characters (or codepoints) found in the byte values for the
string.
An overloaded variant of the function is provided which uses the
PChar type to specify the byte values in the string. Internally,
the String variant casts its value a PChar type and calls the overloaded
variant.
UTF8Length iterates over the bytes in the UTF-8-encoded string data, and calls UTF8CodepointSize to determine the number of bytes needed for each codepoint. Use UTF8LengthFast for a version of the routine optimized for speed.
See also
An experiment, built from Lazarus main 2dfa93c66e of 10-22-2026. Not the official Lazarus documentation.
