Here is source code of the C# Program to Find the Frequency of the Word ʺtheʺ in a given Sentence. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.
* C# Program to Find the Frequency of the Word ʺtheʺ in a given Sentence
public static void Main()
Console.WriteLine("Enter the String : ");
s1 = Console.ReadLine();
public static class counting
public static int CountStringOccurrences(string text, string pattern)
int count = 0;
int i = 0;
while ((i = text.IndexOf(pattern, i)) != -1)
i += pattern.Length;
Here is the output of the C# Program:
Enter the String : we only loop once over the source, which reduces the cost of the method. 3
Sanfoundry Global Education & Learning Series – 1000 C# Programs.