Sha256: ff7bdf2f3331e7f07fb75046d5d41f87b33eb5fbd1f2738ed103202ce0c0c7fb
Contents?: true
Size: 672 Bytes
Versions: 117
Compression:
Stored size: 672 Bytes
Contents
using System; using System.Text.RegularExpressions; using System.Collections.Generic; public static class Phrase { public static IDictionary<string, int> WordCount(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
117 entries across 117 versions & 1 rubygems