Click here to Skip to main content
15,905,238 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this code to generate frequency of words and arrange them according to the higher frequency... it works completely fine but some of the words like "and" "or" "a" "the" are irrelevant. i want to delete them along with there frequency. Need some assistance..

C#
String[] arr = targetListBox.Text.Split(' ');
Dictionary<string, int> dic = new Dictionary<string, int>();
dic = mkCount(arr, dic);
StringBuilder sb = new StringBuilder();
var sortedDict = (from entry in dic orderby entry.Value descending select entry).ToDictionary(pair => pair.Key, pair => pair.Value);
//richTextBox1.Text="Most Frequent Terms in the File: " + targetListBox.Text + " ";
foreach (KeyValuePair<string, int> pair in sortedDict)
{

    // Output the most frequently occurring words and the associated word counts
    sb.AppendLine(pair.Key + " " + pair.Value + " ");
    richTextBox1.Text = sb.ToString();


}
Posted
Comments
BillWoodruff 5-Feb-15 12:03pm    
Dictionary<string, int=""> dic = new Dictionary<string, int="">();
dic = mkCount(arr, dic);

This code puzzles me: first you initialize 'dic to a new instance, then you immediately assign it to the output of some function. Of course, you don't show that function.

1 solution

adding this before code worked. :)
C#
string[] arrToCheck = new string[] {"and","or","a" };
                StringBuilder input = new StringBuilder(targetListBox.Text);
                foreach (string word in arrToCheck )
                {
                    input.Replace(word, string.Empty);
                }
                targetTextBox2.Text = input.ToString();
 
Share this answer
 
Comments
TheRealSteveJudge 5-Feb-15 7:23am    
Do not answer your own questions.
BillWoodruff 5-Feb-15 12:01pm    
@TheRealSteveJudge It is okay for an OP to answer their own questions; this has been discussed before in the "Bugs / Suggestions" forum. If, however, you think someone is asking a question just to answer to get reputation points, or something seems "fishy;" then do report what you observe on the "Spam and Abuse Watch" forum.
TheRealSteveJudge 6-Feb-15 2:34am    
@BillWoodruff:
Thank you for the hint. I did not know that such thing is allowed.
Best regards.
Asad_Iqbal 5-Feb-15 7:30am    
i found an answer to my question so i answered it.. may b someone else problem can b solved because of it.. you don't need to reply with irrelevant comments.
TheRealSteveJudge 6-Feb-15 2:33am    
Congratulations! This is the fourth time you answered your own question.
Do not forget to mark it as solution.
Have a nice day!

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