private static readonly Regex NonSymbols = new Regex("([a-zA-Z0-9]+)", RegexOptions.Compiled); // Words without symbols.
//private static readonly Regex NonSymbols = new Regex("(\S+)", RegexOptions.Compiled); // Any words.
static IEnumerable<string> GetUniqueWords(string input)
{
return AllWord(input).Distinct();
}
static IEnumerable<string> AllWord(string input)
{
return NonSymbols.Matches(input.ToLower()).OfType<Match>().Select(s => s.Value);
}
static long LargestSingleWordCount(string input)
{
IEnumerable<string> words = AllWord(input);
return words.Distinct().Max(s => words.Count(t => t == s));
}
Comments
0 B
|👍
/👎