using System.Collections.Generic;
using System.Text.RegularExpressions;
public static void Main()
Dictionary<string,int> wordFreqs = CountWords("the red fox hacked into the computer of the other red fox");
foreach (KeyValuePair<string,int> d in wordFreqs) {
Console.WriteLine($"word: {d.Key}, count: {d.Value}");
static Dictionary<string,int> CountWords(string text) {
Dictionary<string,int> wordFreqs = new Dictionary<string,int>();
string[] words = Regex.Split(text, @"\W+");
foreach (string word in words) {
if (wordFreqs.ContainsKey(word)) {
wordFreqs[word] = wordFreqs[word] + 1;