Advertisement
Brick

String Helpers

Sep 30th, 2015
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.74 KB | None | 0 0
  1.         private static readonly Regex NonSymbols = new Regex("([a-zA-Z0-9]+)", RegexOptions.Compiled); // Words without symbols.
  2.     //private static readonly Regex NonSymbols = new Regex("(\S+)", RegexOptions.Compiled); // Any words.
  3.  
  4.         static IEnumerable<string> GetUniqueWords(string input)
  5.         {
  6.             return AllWord(input).Distinct();
  7.         }
  8.  
  9.         static IEnumerable<string> AllWord(string input)
  10.         {
  11.             return NonSymbols.Matches(input.ToLower()).OfType<Match>().Select(s => s.Value);
  12.         }
  13.  
  14.         static long LargestSingleWordCount(string input)
  15.         {
  16.             IEnumerable<string> words = AllWord(input);
  17.             return words.Distinct().Max(s => words.Count(t => t == s));
  18.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement