OK - first things first, I'm remote from my Delphi compiler, so this is off the top of my head...you may need to fix a couple of compile time typos :-)
You'll need two TListBox components on a form and the following code behind a button:
begin
ListBox1.Sorted := true;
count := 1;
lastString := '';
for i:=0 to ListBox1.Items.Count-1 do begin
thisString := ListBox1.Items[i];
if thisString = lastString then
count := count + 1
else
if lastString <> '' then begin
ListBox2.Items.Add(lastString + ' ' + IntToStr(count));
count := 1;
end;
// Added
lastString := thisString;
end;
if count > 1 then
ListBox2.Items.Add(lastString + ' ' + IntToStr(count));
end;
The key is to sort the listbox, then look for duplicate strings that are adjacent to each other.
Anyway, it's not the best way of weeding out duplicates, but it should give you enough to get you started.
HTH
Enter your message below
Sign in or Join us (it's free).