Duplicates

Use this forum for everything concerning script usage
Post Reply
atagal
Newbie
Newbie
Posts: 34
Joined: Tue Oct 26, 2010 12:08 am

Duplicates

Post by atagal »

Dimitris, how to remove duplicates in delphi?

Code: Select all

       lbl := TStringList.Create;
       lbl.Duplicates := dupIgnore;
       lbl.Sorted := True;

       i := 0;
       repeat
               sqrNum := GetPart (sCat, i, ';');
               if (sqrNum <> '') then lbl.Add(trim(sqrNum));
               i := i + 1;
       until sqrNum = '';

       sCat := lbl.CommaText;
       lbl.Free;
after many hours i finaly have found some solution but it works with "Sorted=True" only.

on discogs are a lot dublicates labels.
for example:
Cat1, Cat2, Cat3
Label1, Label1, Label2

i wish remove duplicates but not sort it. any hint?

User avatar
jtclipper
Administrator
Administrator
Posts: 768
Joined: Tue Aug 10, 2010 12:04 pm

Re: Duplicates

Post by jtclipper »

From a quick look I think you can use a for loop to iterate through the stringlist, check the value against the entries and add accordingly.

Code: Select all

 procedure _add_to_list;
 var 
   j: integer;
 begin
   if (sqrNum = '') then exit; // get out
   for j := 0 to lbl.Count - 1 do begin
       if lbl.Strings[ j ] = sqrNum then exit; //get out
   end;
   lbl.Add( sqrNum );
 end;


 lbl := TStringList.Create;

 i := 0;
 repeat
    sqrNum := Trim( GetPart(sCat, i, ';') );
    _add_to_list;
    Inc( i );
 until sqrNum = '';

 sCat := lbl.CommaText;
 lbl.Free;
Dimitris

atagal
Newbie
Newbie
Posts: 34
Joined: Tue Oct 26, 2010 12:08 am

Re: Duplicates

Post by atagal »

perfect! thank you!

Post Reply