Sha256: d9dbb5cabe1cbad183896252359b858ff214938ac08a6e8830f916de8582f7b2
Contents?: true
Size: 676 Bytes
Versions: 28
Compression:
Stored size: 676 Bytes
Contents
using System; using System.Text.RegularExpressions; using System.Collections.Generic; public static class WordCount { public static IDictionary<string, int> CountWords(string phrase) { if (phrase == null) throw new ArgumentNullException("phrase"); var counts = new Dictionary<string, int>(); Match match = Regex.Match(phrase.ToLower(), @"\w+'\w+|\w+"); while(match.Success) { string word = match.Value; if(!counts.ContainsKey(word)) { counts[word] = 0; } counts[word]++; match = match.NextMatch(); } return counts; } }
Version data entries
28 entries across 28 versions & 1 rubygems