Brick icon

String Helpers

Brick | PRO | 09/30/15 07:31:01 PM UTC | 0 ⭐ | 222 👁️ | Never ⏰ | []
C# |

740 B

|

None

|

0 👍

/

0 👎

        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

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎