Einzelnen Beitrag anzeigen

DieHardMan

Registriert seit: 16. Jul 2002
Ort: Stuttgart
68 Beiträge
 
#5

Re: Strings schnell auf Ähnlichkeit überprüfen

  Alt 12. Feb 2006, 01:17
Ja hab ich, habs auch versucht aber irgendwie net hinbekommen.

Delphi-Quellcode:
procedure TfrmMain.Button1Click(Sender: TObject);
var
  i, a, Minimum, Maximum, Distance, MaxDistance, LengthFirstString,
    LengthSecondString: Integer;
begin
  MaxDistance := 15;

  For i := 0 to lstRSSData.Items.Count - 1 do
  begin
    LengthFirstString := Length(lstRSSData.Items.Item[i].SubItems.Strings[3]);
    Minimum := LengthFirstString - (MaxDistance * LengthFirstString div 100);
    Maximum := LengthFirstString + (MaxDistance * LengthFirstString div 100);

    For a := i to lstRSSData.Items.Count - 1 do
      If a <> i then
      begin
        LengthSecondString := Length(lstRSSData.Items.Item[a].SubItems.Strings[3]);
        If (LengthSecondString >= Minimum) and
          (LengthSecondString <= Maximum) then
        begin
// ShowMessage(IntToStr(LengthFirstString) + #13#10 + IntToStr(temp1) +
// #13#10 + IntToStr(temp2));
          distance := Levenshtein(lstRSSData.Items.Item[i].SubItems.Strings[3],
            lstRSSData.Items.Item[a].SubItems.Strings[3]);
          If distance <= maxdistance then
            ShowMessage('Duplicate text found!' + #13#10#13#10 + 'i' +
              IntToStr(i) + ': ' + #13#10 +
              lstRSSData.Items.Item[i].SubItems.Strings[2] +
              #13#10#13#10 + 'a' + IntToStr(a) + ': ' + #13#10 +
              lstRSSData.Items.Item[a].SubItems.Strings[2] + #13#10#13#10 +
              'Difference: ' + IntToStr(distance) + ' %');
        end;
      end;
  end;
end;
Alle meine Entchen...
  Mit Zitat antworten Zitat