using System.Text.RegularExpressions; using System.Collections.Generic; class Phrase { public static Dictionary WordCount(string phrase) { Dictionary ret = new Dictionary(); Regex rgx = new Regex("[^a-zA-Z0-9 ,']"); phrase = rgx.Replace(phrase, ""); string[] words = Regex.Split(phrase, @"[\s,]"); char[] trimChars = new char[2]; trimChars[0] = ' '; trimChars[1] = '\''; foreach(string wrd in words) { string normWrd = wrd.ToLower().Trim(trimChars); if(normWrd != "") { int num = 0; if(ret.ContainsKey(normWrd)) { ret.TryGetValue(normWrd, out num); ret.Remove(normWrd); } num++; ret.Add(normWrd, num); } } return ret; } }