Sign in Join
FPDoc Onlineexperiment

UTF8Insert procedure

In unit LazUTF8

Inserts the specified UTF-8 values into a string at the specified character position.

Declaration

pascal
procedure UTF8Insert(const source: Utf8String; var s: Utf8String; 
 StartCharIndex: PtrInt)

Description

UTF8Insert inserts the specified values into a string at the specified character position. UTF8Insert is an overloaded procedure. The variants allow the string arguments to be specified as either String or UTF8String types.

source is the UTF-8-encoded values inserted in the routine.

s is the string where the values from source are inserted at the specified character position.

The value in StartCharIndex starts at 1, and represents the n-th codepoint (or character) in the destination string (s) where the values are inserted. If StartCharIndex contains a value less than 1, it is converted to the value 1 (just like in the RTL Insert routine).

UTF8Insert calls UTF8CodepointStart to determine the position in s where the codepoint represented by StartCharIndex is located. The RTL Insert routine is called to insert the UTF-8-encoded values from source into s at the required position. If s is an empty UTF-8 string or the specified character index does not exist, the value in source is appended to the value in s.

Modified in LazUtils version 4.0 to ensure that: StartCharIndex starts at 1 (for String-style indexing) and not 0 (for PChar-style indexing), the value is appended when the character index is not found.

See also

An experiment, built from Lazarus main 2dfa93c66e of 10-22-2026. Not the official Lazarus documentation.