Einzelnen Beitrag anzeigen

omata

Registriert seit: 26. Aug 2004
Ort: Nebel auf Amrum
3.154 Beiträge
 
Delphi 7 Enterprise
 
#20

Re: PosExUltra - Ultimative Stringsuche/Parser

  Alt 22. Feb 2010, 11:24
Zitat von GPRSNerd:
da hat sich ein kleiner Copy&Paste-Fehler in der 2. Procedure versteckt...
Zitat von Hawkeye219:
...kommt es zu einer Endlosschleife ... Im Code von alzaimar war dieser Fall durch eine Exit-Anweisung abgedeckt.
Ups, ja ihr habt recht, danke für die Hinweise.

Hier die Korrektur...
Delphi-Quellcode:
procedure ExtractBetween(const aSource, aPrefix, aSuffix : string;
                         aFindAll : Boolean; aNewPrefix, aNewSuffix : string;
                         aWords : TStrings);
var
  PrefixLength, PosPrefix, PosSuffix, BestPos : Integer;
begin
  PosPrefix := PosEx(aPrefix, aSource, 1);
  if PosPrefix > 0 then begin
    PrefixLength := Length (aPrefix);
    repeat
      PosSuffix := PosEx(aSuffix, aSource, PosPrefix + PrefixLength);
      if PosSuffix > 0 then begin
        while (PosPrefix <> 0) and (PosPrefix < PosSuffix) do begin
          BestPos := PosPrefix;
          PosPrefix := PosEx(aPrefix, aSource, PosPrefix + PrefixLength);
        end;
        aWords.Append(
            aNewPrefix
          + Copy(aSource, BestPos + PrefixLength, PosSuffix-BestPos - PrefixLength)
          + aNewSuffix
        );
      end;
    until not aFindall or (PosSuffix = 0) or (PosPrefix = 0);
  end;
end;
  Mit Zitat antworten Zitat