Jak usunąć duplikaty z listbox w poziomie

0

Przypuśćmy, ze w listbox mam pewne znaki:

2011-11-01 a b c d => [1][2][2][1]
2011-11-02 a c d f => [1][4][2][4]
2011-11-03 f d d g => [1][2][2][1]
2011-11-04 a b c d => [3][2][3][1]
2011-11-05 a b c d => [3][3][3][1]

a powinno być dla mnie

2011-11-01 a b c d => [1][2]
2011-11-02 a c d f => [1][2][4]
2011-11-03 f d d g => [1][2]
2011-11-04 a b c d => [3][2][1]
2011-11-05 a b c d => [3][1]

chodzi mi o usunięcie duplikatów po znaku =>

Dla [1] Robię tak:

implementation

{$R *.dfm}

function CountPos(const subtext: string; Text: string): Integer;
 begin
   if (Length(subtext) = 0) or (Length(Text) = 0) or (Pos(subtext, Text) = 0) then
     Result := 0
   else
     result := (Length(Text) - Length(StringReplace(Text, subtext, '', [rfReplaceAll]))) div
       Length(subtext);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
i  : integer;
s : string;
sl : TStringList;
begin
sl := TStringList.Create;
sl.Clear;
sl.Text := ListBox1.Items.Text;

  for i := 0 to ListBox1.Items.Count -1  do
   begin
    s := inttostr(countpos('[1]', copy(sl[i],22,1000)));
    if s > '1' then
    sl[i] := copy(sl[i],0,22) + StringReplace(copy(sl[i],23,1000), '[1]', '', []);

    ListBox1.items.text := sl.text;
   end;

   sl.free;
end;

gdyby się okazało że :

2011-11-01 a b c d => [1][2][2][1][1]

to musiałbym wcisnąć drugi raz button.

0

A jak brzmi pytanie?

0

Poradziłem sobie :)

var
i  : integer;
s1, s2, s3, s4, s5 : string;
sl : TStringList;
begin
sl := TStringList.Create;
sl.Clear;
sl.Text := ListBox1.Items.Text;

 repeat

  for i := 0 to ListBox1.Items.Count -1  do
   begin
    s1 := inttostr(countpos('[1]', copy(sl[i],22,1000)));
    s2 := inttostr(countpos('[2]', copy(sl[i],22,1000)));
    s3 := inttostr(countpos('[3]', copy(sl[i],22,1000)));
    s4 := inttostr(countpos('[4]', copy(sl[i],22,1000)));

    if s1 > '1' then sl[i] := copy(sl[i],0,22) + StringReplace(copy(sl[i],23,1000), '[1]', '', []);
    if s2 > '1' then sl[i] := copy(sl[i],0,22) + StringReplace(copy(sl[i],23,1000), '[2]', '', []);
    if s3 > '1' then sl[i] := copy(sl[i],0,22) + StringReplace(copy(sl[i],23,1000), '[3]', '', []);
    if s4 > '1' then sl[i] := copy(sl[i],0,22) + StringReplace(copy(sl[i],23,1000), '[4]', '', []);

     s5 := inttostr(strtoint(s1) + strtoint(s2) + strtoint(s3) + strtoint(s4));

   end;

 until (s5 = '2') ;

   ListBox1.items.text := sl.text;
   sl.free;
 end;

1 użytkowników online, w tym zalogowanych: 0, gości: 1, botów: 0