using System;
class frequencyword {
public static void Main() {
string s1;
Console.WriteLine("Enter the String : ");
s1 = Console.ReadLine();
Console.WriteLine(counting.CountStrFrequency(s1, "test"));
Console.ReadKey();
}
}
public static class counting {
public static int CountStrFrequency(string text, string pattern) {
int count = 0;
int i = 0;
while ((i = text.IndexOf(pattern, i)) != -1) {
i += pattern.Length;
count++;
}
return count;
}
}This program is useful to Count the number of string frequency in a sentence using C#.
