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

Version Path
trackler-2.2.1.14 tracks/csharp/exercises/word-count/Example.cs
trackler-2.2.1.13 tracks/csharp/exercises/word-count/Example.cs
trackler-2.2.1.12 tracks/csharp/exercises/word-count/Example.cs
trackler-2.2.1.11 tracks/csharp/exercises/word-count/Example.cs
trackler-2.2.1.10 tracks/csharp/exercises/word-count/Example.cs
trackler-2.2.1.9 tracks/csharp/exercises/word-count/Example.cs
trackler-2.2.1.8 tracks/csharp/exercises/word-count/Example.cs
trackler-2.2.1.7 tracks/csharp/exercises/word-count/Example.cs
trackler-2.2.1.6 tracks/csharp/exercises/word-count/Example.cs
trackler-2.2.1.5 tracks/csharp/exercises/word-count/Example.cs
trackler-2.2.1.4 tracks/csharp/exercises/word-count/Example.cs
trackler-2.2.1.3 tracks/csharp/exercises/word-count/Example.cs
trackler-2.2.1.2 tracks/csharp/exercises/word-count/Example.cs
trackler-2.2.1.1 tracks/csharp/exercises/word-count/Example.cs
trackler-2.2.1.0 tracks/csharp/exercises/word-count/Example.cs
trackler-2.2.0.6 tracks/csharp/exercises/word-count/Example.cs
trackler-2.2.0.5 tracks/csharp/exercises/word-count/Example.cs
trackler-2.2.0.4 tracks/csharp/exercises/word-count/Example.cs
trackler-2.2.0.3 tracks/csharp/exercises/word-count/Example.cs
trackler-2.2.0.2 tracks/csharp/exercises/word-count/Example.cs