473,387 Members | 1,465 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

String average ?

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
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #1
1 1288
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

"Chris Wertman" <cw******@yahoo.com> wrote in message
news:OW****************@TK2MSFTNGP09.phx.gbl...
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
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Tatu Portin | last post by:
Have this kind of struct: typedef struct { char **user_comments; /* ... */ } vorbis_comment; /* prototype */ char * read_vorbis_string ( FILE *sc);
3
by: Robert Blackwell | last post by:
What am I doing wrong here? using System; namespace SchoolStuff { class BodyFat { public static void Main()
6
by: J | last post by:
Kind of new at programming/vb.net. I'm doing this junky die roller program. Heres's what is supposed to happen: Roll 2 6-sided dies. Add rolls together put total in rolls(d6total). Display...
10
by: Tom E. | last post by:
Hello, I would like to know what the most efficient way is to count words in a string and to determine what the average word length is. I know this can be done in a array, but is there an easier...
4
by: Gary | last post by:
Hi, I have a temperature conversion program down pat, but I was told to add an average, meaning, i need to get the average temperature for as many times as it was entered. i do not know where to...
4
by: Chris | last post by:
Hi Everyone, I am using a regex to check for a string. When all the file contains is my test string the regex returns a match, but when I embed the test string in the middle of a text file a...
26
by: Hardy Wang | last post by:
Hi all, I know it is better to handle large string with a StringBuilder, but how does StringBuilder class improve the performance in the background? Thanks! -- WWW:...
3
by: Salad | last post by:
http://www.mathwords.com/w/weighted_average.htm At the above link gives an example of a weighted average. It uses the following example: Grades are often computed using a weighted average....
2
by: Shawn Minisall | last post by:
I'm trying to unpack a list of 5 floats from a list read from a file and python is telling me 5 variables are too many for the string.split statement. Anyone have any other idea's? NOTE: the only...
4
by: dacuteangel04 | last post by:
ok what my program is suppost to do is open a file - Grades.txt and read each line the breaking the lines down w/ tokens so i may later average some numbers an example some of the lines from the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.