Find The Most Occurred Word In String

  1. public string ReturnRepeatElement(string str)                       
  2. {  
  3.     int i, j;  
  4.     int maxcount = 0;  
  5.     string[] strArray = new string[]{};  
  6.     string _element=string.Empty;  
  7.     strArray = str .Split(' ');  
  8.     for ( i = 0; i < strArray.Length; i++)  
  9.     {  
  10.         int count = 0;  
  11.         for ( j = 0; j < strArray.Length;j++ )  
  12.         {  
  13.             if (strArray[i] == strArray[j])  
  14.             {  
  15.                 count++;  
  16.                          
  17.             }  
  18.                       
  19.         }  
  20.         if (maxcount < count)  
  21.         {  
  22.            maxcount = count;  
  23.            _element=strArray[i];  
  24.         }  
  25.     }  
  26.   
  27.     return _element;  
  28. }