[Solved] How to count 2 or 3 letter words in a string using asp c#


You can try something like this:

  • split sentence by space to get array of words
  • group them by length of word (and order by that length)
  • iterate through every group and write letter count and number of words with that letter count

code

using System.Linq;
using System.Diagnostics;
...

var words = value.Split(' ');
var groupedByLength = words.GroupBy(w => w.Length).OrderBy(x => x.Key);
foreach (var grp in groupedByLength)
{
    Debug.WriteLine(string.Format("{0} letter words: {1}", grp.Key, grp.Count()));
}

0

solved How to count 2 or 3 letter words in a string using asp c#