Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
pls tell me how to find frequency of the given words c#.net
Posted

1 solution

This looks like a homework assignment, and we don't generally do homework for people here. However, that thought hand't occurred to me before I came up with the answer, so consider yourself lucky thata you got a response at all.
FWIW, you should find another isntructor because he's not teaching you the arguably most important programmer skill - analysis.

-------------

Split the string into an collection of words, and then use LINQ to count the number of instances of a given word.

string mywordString = "around the rugged rock the ragged rascal ran";
string findWord = "the";

// at this point, you probably want to remove everything that's not a 
// space or alhanumeric character. You can probably come up eith a 
// regex object for that.

List<string> words = new List<string>();
words.Add(words.ToLower().Split(" "));
findWord = findWord.ToLower();

int count = (from word in words 
             where word == findWord 
             select word).Count();


You may have to tweak it a little, but it provides the gist of how you could approach the problem.
 
Share this answer
 
Comments
Kasunmit 2-Aug-10 13:08pm    
sry for the bad question but ur answer will help me a lot ... i asked that y i need it urgently without that i can t proceed Thank you very much for ur help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900