#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    29
    Rep Power
    0

    Removing duplicates of a .txt file then send them to combobox


    Hello fellas.

    I have a .txt file having names.


    I want to remove duplicates then send them to the combobox.

    For example: A "names.txt" file has the following data:
    michael
    michael
    michael
    james
    james
    john
    cindy
    cindy
    .
    .

    it will be in format, duplicates removed:
    michael
    james
    john
    cindy

    then I will send them to the combobox.

    how could I remove duplicates.

    please help.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2006
    Location
    Carlsbad, CA
    Posts
    2,055
    Rep Power
    383
    how could I remove duplicates.
    It depends upon whether the items in your combobox must maintain their original order or whether they can be sorted.

    If they can be sorted then all you need to do is something like this
    pseudo code:

    Code:
    var
      tmpList: TStringList;
    begin
       tmpList := TStringList.Create;
       try
         tmpList.Sorted := True;
         tmpList.Duplicates := duIgnore;
         // Now add your items from file to tmpList
         // Duplicates will be ignored
         comboBox1.Items.Assign(tmpList);
        finally
           tmpList.Free;
        end;
    end;
    NOTE: Code above not tested or checked in any way; but the process is correct.

    If you do NOT want the items sorted then you will either have to store the original order and re-arrange the items
    or write your own algorithm for removing duplicates which, for efficiency, may depend
    upon your knowledge of how duplicates may be separated in the file.

    Clive
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    29
    Rep Power
    0
    works perfectly.

    thanks.

IMN logo majestic logo threadwatch logo seochat tools logo