String average ?

  • Thread starter Thread starter Chris Wertman
  • Start date Start date
C

Chris Wertman

Im a little stuck on an efficent way to do this.
Say I have an array of strings , or a simple list whatever. Like this

Del Rey
Dell Ray
DelRey
Del Rey
Del Rey
Del Ray

Now what I would want to do is return Del Rey as it is the most used
string in the array. For many of the things I will be looking for , well
actually all of them they are free form text returned from a page
scrape.

Ive though about puttting them in a temp table , doing a distinct then
counting occurances , but well that seems a little ugly even though it
seem like it woul work. Are there any BETTER ways of doin this ? I will
always have an unknown quantity in the list.

Chris
 
Chris,
Have you considered using a HashTable, where the string itself is the key to
the HashTable, and the number of occurrences is the value?

Then for each string in your list, you check for that string as a key in the
HashTable, if its found you increment the value, otherwise you add the
string as a new key with the value of 1.

When you are all done adding values, you can use a For Each loop to find the
highest value, saving the key...

You could probably do the same thing with a DataTable, that is keyed by the
string, with a second value that represents the count.

Hope this helps
Jay
 
Back
Top