Number Of String Word Frequency In A Sentence Using C#

  1. using System;  
  2. class frequencyword {  
  3.     public static void Main() {  
  4.         string s1;  
  5.         Console.WriteLine("Enter the String : ");  
  6.         s1 = Console.ReadLine();  
  7.         Console.WriteLine(counting.CountStrFrequency(s1, "test"));  
  8.         Console.ReadKey();  
  9.     }  
  10. }  
  11. public static class counting {  
  12.     public static int CountStrFrequency(string text, string pattern) {  
  13.         int count = 0;  
  14.         int i = 0;  
  15.         while ((i = text.IndexOf(pattern, i)) != -1) {  
  16.             i += pattern.Length;  
  17.             count++;  
  18.         }  
  19.         return count;  
  20.     }  
  21. }