Most Common Words using LINQ

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 1598 Views - Last Post: 17 June 2013 - 06:09 PM Rate Topic: -----

#16 ianpb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 11-July 12

Re: Most Common Words using LINQ

Posted 17 June 2013 - 06:09 PM

Thanks and got this things right finally.... :whistling:

 public void MostUsedWords()
        {
            string sentence;
            sentence = txtParagraph.Text;
            char[] delimiters = new char[] { ' ', '.', '?', '!', '\r', '\n' };
            var words = sentence.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);

            var wordFreqs = words.GroupBy(word => word).OrderByDescending(wordgroup => wordgroup.Count());
            var mostPop = wordFreqs.FirstOrDefault();
            var theMostPop = wordFreqs.TakeWhile(wf => wf.Count() == mostPop.Count());
            foreach (var wordFreq in theMostPop)
            {

                txtFreqWord.Text = txtFreqWord.Text + wordFreq.Key.ToString() + ", ";   
            }

        }



Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2