UTF8StringReplace function
Replaces one or more values in a UTF-8-encoded string which match a given pattern.
Declaration
function UTF8StringReplace(const S: string; const OldPattern: string;
const NewPattern: string;
Flags: TReplaceFlags;
const ALanguage: string='') : stringDescription
UTF8StringReplace is an overloaded
String function
which replaces values in a string matching a given pattern.
S is the UTF-8-encoded string to update in the function.
OldPattern is a pattern with the values to be replaced in S.
NewPattern is the replacement value for OldPattern in S.
Flags contains
TReplaceFlags values and control the
options enabled in the operation.
rfIgnoreCase causes
case-insensitive comparisons to be used for values in S and OldPattern; both
values are converted to lowercase copies for the purpose.
rfReplaceAll causes all occurrences of OldPattern to be replaced
with NewPattern in S. If the flag is omitted, only the first occurrence of
OldPattern in S is replaced in the routine.
ALanguage is the 2-digit ISO 639-1 Language Code, like 'es' or
'de', used when converting values to lowercase for case-insensitive search.
The default value is an empty string ('') and offers maximum speed when the
language is not significant.
Count is an output variable used to return the actual number of
replacements performed in the function.
UTF8StringReplace provides support for UTF-8 codepoints which have different sizes (byte counts) for the uppercase and lowercase variants of patterns. It ensures that the return value is resized (when needed) to account for individual codepoint sizes altered in S due to case conversion.
The return value is a UTF-8-encoded string with the updated values from S following replacements.
No actions are performed in the routine if OldPattern is an empty string ('').
An experiment, built from Lazarus main 2dfa93c66e of 10-22-2026. Not the official Lazarus documentation.
