Sha256: 728b7998533411e842ee6739d38c5fd7befb3f4ba70e2a5920398909534dbe40
Contents?: true
Size: 676 Bytes
Versions: 136
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
136 entries across 136 versions & 1 rubygems