<< ibec_QuotedStr | IBEBlock | ibec_AnsiStringToUTF8 >>

ibec_StringReplace

Returns a string with occurrences of one substring replaced by another substring.

Syntax

 function ibec_StringReplace(const S, OldPattern, NewPattern: string; Flags: integer): string;

Description

ibec_StringReplace replaces occurrences of the substring specified by OldPattern with the substring specified by NewPattern. ibec_StringReplace assumes that the source string, specified by S, may contain Multibyte characters.

If the Flags parameter does not include ReplaceAll, ibec_StringReplace only replaces the first occurrence of OldPattern in S. Otherwise, all instances of OldPattern are replaced by NewPattern.

If the Flags parameter includes IgnoreCase, the comparison operation is case insensitive.

The performance of the ibec_StringReplace function has been greatly improved; it is now about 10 times faster than when originally introduced.

Example

 execute ibeblock
 as
 begin
   s = 'AAA BBB aaa bbb AAA';
   -- Replace only the first occurrence of 'AAA' with 'CCC'
   news = ibec_StringReplace(s, 'AAA', 'CCC', 0);  -- news =  'CCC BBB aaa bbb AAA'
   -- Replace all occurrences of 'AAA' with 'CCC'
   news = ibec_StringReplace(s, 'AAA', 'CCC', __rfReplaceAll); -- news =  'CCC BBB aaa bbb CCC'
   -- Replace all occurrences of 'BBB' and 'bbb' with 'CCC' (case insensitive replace)
   news = ibec_StringReplace(s, 'BBB', 'CCC', __rfReplaceAll + __rfIgnoreCase); -- news =  'AAA CCC aaa CCC AAA'
 end

back to top of page
<< ibec_QuotedStr | IBEBlock | ibec_AnsiStringToUTF8 >>