Sha256: 3a69114db672c9a60c23ab38f1a0863bacded1d8a9136b3fca982e9492584248
Contents?: true
Size: 665 Bytes
Versions: 115
Compression:
Stored size: 665 Bytes
Contents
using System; using System.Text.RegularExpressions; using System.Collections.Generic; public 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
115 entries across 115 versions & 1 rubygems