I don't believe .net can't do this...

Soldato
Joined
18 Oct 2002
Posts
7,139
Location
Ironing
I've got a data source that I pull a whole list of words out of. I just need to count how many times each word comes out and then return the top 10 or so. Easy? Apparently not.

My first thought was to throw everything into some sort of hash or collection, with the word string as the key and the number of times it has appeared as the value. However, there is no class like that which lets you sort by value to return the highest 10. The only way I could think of doing it is throwing the name/value pairs into a hashtable, going through each one and then adding the index of the hashtable key into an arraylist comparing it's value with every existing entry in the arraylist to see where it should go. I'd then end up with an arraylist containig the sorted indexes of the keys in the hashtable. A fairly bad way of doing it.

Any ideas?
 
The problem is that all the words are stored in a column of a table, but there might be more than one word in each row, space separated. THerefore, one cell might contain "bunny wopt hacksaw" whereas the next row may be NULL and the next one might contain just one word. I need to get the complete list of individual words out, and because this involves splitting, I was under the impression the database couldn't do this...
 
I've got into this habit of thinking up really good reasons for doing something one way, and then forgetting it. There was a very very very (I assure you) very good reason for putting the words in this way, but the reason for doing that over a normal table has escaped me.

What I'll probably do now is re-engineer the whole thing to have the tags in a separate table, and then when I'm 80% done remember the reason why I'm not doing it that way. I'll get back to you lot then...
 
You're right, I think I was on drugs or something when I did that. I've re-engineered it and overcome the problem that I thought was a lot bigger than it actually was.

Trivial now. Thanks everyone.
 
Back
Top Bottom