Einzelnen Beitrag anzeigen

alzaimar
(Moderator)

Registriert seit: 6. Mai 2005
Ort: Berlin
4.956 Beiträge
 
Delphi 2007 Enterprise
 
#14

Re: PosExUltra - Ultimative Stringsuche/Parser

  Alt 21. Feb 2010, 20:19
So, ich hab mich auch mal versucht und kurz getestet.
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 exit;
  PrefixLength := Length (aPrefix);
  Repeat
    PosSuffix := PosEx (aSuffix, aSource, PosPrefix + PrefixLength);
    if PosSuffix=0 then Exit;

    While (PosPrefix<>0) and (PosPrefix<PosSuffix) Do Begin
      BestPos := PosPrefix;
      PosPrefix := PosEx (aPrefix, aSource, PosPrefix + PrefixLength);
    End;
    sWords.Add (aNewPrefix + Copy (aSource, BestPos+PrefixLength,PosSuffix-BestPos-PrefixLength) + aNewSuffix);
    If PosPrefix=0 then exit;
  Until not aFindall;
End;
Die ganzen Sonderfälle (leere Suchstrings usw) habe ich nicht abgefangen.
"Wenn ist das Nunstruck git und Slotermeyer? Ja! Beiherhund das Oder die Flipperwaldt gersput!"
(Monty Python "Joke Warefare")
  Mit Zitat antworten Zitat