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.1.0.37 tracks/csharp/exercises/word-count/Example.cs
trackler-2.1.0.36 tracks/csharp/exercises/word-count/Example.cs
trackler-2.1.0.34 tracks/csharp/exercises/word-count/Example.cs
trackler-2.1.0.33 tracks/csharp/exercises/word-count/Example.cs
trackler-2.1.0.32 tracks/csharp/exercises/word-count/Example.cs
trackler-2.1.0.31 tracks/csharp/exercises/word-count/Example.cs
trackler-2.1.0.30 tracks/csharp/exercises/word-count/Example.cs
trackler-2.1.0.29 tracks/csharp/exercises/word-count/Example.cs
trackler-2.1.0.28 tracks/csharp/exercises/word-count/Example.cs
trackler-2.1.0.27 tracks/csharp/exercises/word-count/Example.cs
trackler-2.1.0.26 tracks/csharp/exercises/word-count/Example.cs
trackler-2.1.0.25 tracks/csharp/exercises/word-count/Example.cs
trackler-2.1.0.24 tracks/csharp/exercises/word-count/Example.cs
trackler-2.1.0.23 tracks/csharp/exercises/word-count/Example.cs
trackler-2.1.0.22 tracks/csharp/exercises/word-count/Example.cs
trackler-2.1.0.21 tracks/csharp/exercises/word-count/Example.cs
trackler-2.1.0.20 tracks/csharp/exercises/word-count/Example.cs
trackler-2.1.0.19 tracks/csharp/exercises/word-count/Example.cs
trackler-2.1.0.18 tracks/csharp/exercises/word-count/Example.cs
trackler-2.1.0.17 tracks/csharp/exercises/word-count/Example.cs