[Overview][Types][Classes][Procedures and functions][Variables][Index] Reference for unit 'LazUTF8' (#lazutils)

UTF8StringReplace

Replaces one or more values in a UTF-8-encoded string which match a given pattern.

Declaration

Source position: lazutf8.pas line 123

function UTF8StringReplace(

  const S: string;

  const OldPattern: string;

  const NewPattern: string;

  Flags: TReplaceFlags;

  const ALanguage: string = ''

):string;

function UTF8StringReplace(

  const S: string;

  const OldPattern: string;

  const NewPattern: string;

  Flags: TReplaceFlags;

  out Count: Integer;

  const ALanguage: string = ''

):string;

Arguments

S

  

Original UTF-8-encoded values to examine.

OldPattern

  

Pattern to replace in the function.

NewPattern

  

Replacement values for the operation.

Flags

  

Replace options enabled in the function.

ALanguage

  

Language Code used for locale-specific lowercase conversions.

Function result

UTF-8-encoded values after the replace operation.

Arguments

S

  

Original UTF-8-encoded values to examine.

OldPattern

  

Pattern to replace in the function.

NewPattern

  

Replacement values for the operation.

Flags

  

Replace options enabled in the function.

Count

  

Number of times the search pattern was replaced in the string.

ALanguage

  

Language Code used for locale-specific lowercase conversions.

Description

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 ('').


Version 4.0 Generated 2025-05-03 Home