Here is my code:
string StringFromTheInput = TextBox1.Text;
string source = StringFromTheInput.ToString();
var frequencies = new Dictionary<string, int>();
frequencies.Add("item", 0);
string highestWord = null;
var message = string.Join(" ", source);
var splichar = new char[] { ' ', '.' };
var single = message.Split(splichar);
int highestFreq = 0;
foreach (var item in single)
{
if (item.Length > 4)
{
int freq;
frequencies.TryGetValue(item, out freq);
freq += 1;
if (freq> highestFreq)
{
highestFreq = freq;
highestWord = item.Trim();
}
frequencies[item] = freq;
Label1.Text = highestWord.ToString();
}
}
This is successfully gets me the most frequent word from the text but I tried to increment highestFreq= freq+1 to get the second most frequent word but it doesn`t work!