Andries, > I'm scrolling through a list of strings one by one (e.g. all words in > a rich edit) and I want to count how much unique words I have and how > often these words have been used.
Sorry I'm joining this thread late. The best answer would depend on several things. About how many words do you typically expect, and what would be the average count for each word? Would the words be in random order, or are they sorted or in some other known order? And did you list all the information you need? If the number of words is fairly small, just about any algorithm would suffice. You could use a sorted TStringList to store the words, IndexOf to see if a word is already in the list, Add to add a new word, and Objects (typecast as an Integer) to increment the count of a word that is already in the list. This algorithm would slow down as the number of words becomes large. For many random-order words with a moderate count (say an average of around 5 per word), I would use a red-black tree to store the words and counts. This is more complicated but would speed up the searching and adding of words. The EZDSL package for Delphi includes code for the red-black tree. The code does have a bug, which I corrected. Let me know if you need more info on this choice or the corrected code. Rory Daulton [email protected]

