View Issue Details

IDProjectCategoryView StatusLast Update
0023987FPCOtherpublic2019-02-18 10:43
ReporterAvishai Assigned ToMichael Van Canneyt  
PrioritynormalSeverityfeatureReproducibilityhave not tried
Status resolvedResolutionfixed 
Target Version3.2.0Fixed in Version3.3.1 
Summary0023987: Suggest adding StringReplaceAll with Replacement Count
DescriptionI would like to suggest adding a new funtion like StringReplace but adding a Replacement Count when rfReplaceAll is used. I copied StringReplace and assume 'rfReplaceAll' and added Count.

function StringReplaceAll(const S, OldPattern, NewPattern: string; Flags: TReplaceFlags; Var Count: Integer): string;
  Srch,OldP,RemS: string;
  P : Integer;
  Count:= 0;
  if rfIgnoreCase in Flags then begin
  while (Length(Srch)<>0) do begin
    P:=AnsiPos(OldP, Srch);
    if P=0 then begin
    end else begin
      //if not (rfReplaceAll in Flags) then begin
      // Result:=Result+RemS;
      // Srch:='';
      //end else
TagsNo tags attached.
Fixed in Revision41330
Attached Files


Bart Broersma

2013-03-05 17:22

reporter   ~0066032

1.) Shouldn't this be in FPC
2.) Count should probably be an out parameter
3.) Maybe better re-use exiting StringReplace, now we get 2 functions with almost identical code to maintain

Bart Broersma

2019-02-15 13:21

reporter   ~0114144

The idea of a Count parameter in StringReplace isn't that bad.
ATM we seem to have multiple implementations/variants of StringReplace with different strategies and different string types and different units (StrUtils, SysUtils).
StringReplaceBoyerMoore already has an internal MatchesCount and so does StringReplaceFast.

Thaddy de Koning

2019-02-15 13:30

reporter   ~0114145

var count should be out count. Good idea.

Bart Broersma

2019-02-15 16:35

reporter   ~0114156

@Michael: I implemented this on the Lazarus side (LazUtils package) in trunk and put the Count parameter after the Flags parameter.
If this is to be implemented in fpc, could you indicate at what position you would put such a parameter, so that the LazUtils signature will be more or less the same (ignore the Language parameter in the Utf8 version)?

Michael Van Canneyt

2019-02-15 17:56

administrator   ~0114158

I intend to put it on the same place: after flags. It will be an overloaded version of StringReplace. I see no need for a second function.

Bart Broersma

2019-02-15 21:27

reporter   ~0114162

> I see no need for a second function.
Of course not, that's what overload is for.

Michael Van Canneyt

2019-02-16 07:55

administrator   ~0114168

Added overloaded version to SysUtils

Issue History

Date Modified Username Field Change
2013-03-03 13:53 Avishai New Issue
2013-03-05 17:22 Bart Broersma Note Added: 0066032
2013-03-05 20:36 Vincent Snijders Project Lazarus => FPC
2019-02-15 13:21 Bart Broersma Note Added: 0114144
2019-02-15 13:30 Thaddy de Koning Note Added: 0114145
2019-02-15 15:48 Michael Van Canneyt Assigned To => Michael Van Canneyt
2019-02-15 15:48 Michael Van Canneyt Status new => assigned
2019-02-15 16:35 Bart Broersma Note Added: 0114156
2019-02-15 17:56 Michael Van Canneyt Note Added: 0114158
2019-02-15 21:27 Bart Broersma Note Added: 0114162
2019-02-16 07:55 Michael Van Canneyt Fixed in Revision => 41330
2019-02-16 07:55 Michael Van Canneyt Note Added: 0114168
2019-02-16 07:55 Michael Van Canneyt Status assigned => resolved
2019-02-16 07:55 Michael Van Canneyt Fixed in Version => 3.3.1
2019-02-16 07:55 Michael Van Canneyt Resolution open => fixed
2019-02-16 07:55 Michael Van Canneyt Target Version => 3.2.0