TIdSysVCL.StringReplace buglet

Giganews Newsgroups
Subject: TIdSysVCL.StringReplace buglet
Posted by:  Tim Parker-Nance (tim_…@hotmail.com)
Date: Wed, 18 May 2005

The version that takes an array has a buglet/feature. The current code is as
follows:

  for i := Low(OldPattern) to High(OldPattern) do
  begin
    Result :=
SysUtils.StringReplace(s,OldPattern[i],NewPattern[i],[rfReplaceAll]);
  end;

The problem is that the result is the last SysUtils.StringReplace. It is not
the accumulation of the n StringReplaces. What it should be is as follows:

  Result := s;
  for i := Low(OldPattern) to High(OldPattern) do
  begin
    Result :=
SysUtils.StringReplace(Result,OldPattern[i],NewPattern[i],[rfReplaceAll]);
  end;

Replies