Sha256: 728b7998533411e842ee6739d38c5fd7befb3f4ba70e2a5920398909534dbe40

Contents?: true

Size: 676 Bytes

Versions: 136

Compression:

Stored size: 676 Bytes

Contents

using System;
using System.Text.RegularExpressions;
using System.Collections.Generic;

public static class WordCount
{
    public static IDictionary<string, int> Countwords(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

136 entries across 136 versions & 1 rubygems

Version Path
trackler-2.2.1.151 tracks/csharp/exercises/word-count/Example.cs
trackler-2.2.1.150 tracks/csharp/exercises/word-count/Example.cs
trackler-2.2.1.149 tracks/csharp/exercises/word-count/Example.cs
trackler-2.2.1.148 tracks/csharp/exercises/word-count/Example.cs
trackler-2.2.1.147 tracks/csharp/exercises/word-count/Example.cs
trackler-2.2.1.146 tracks/csharp/exercises/word-count/Example.cs
trackler-2.2.1.145 tracks/csharp/exercises/word-count/Example.cs
trackler-2.2.1.144 tracks/csharp/exercises/word-count/Example.cs
trackler-2.2.1.143 tracks/csharp/exercises/word-count/Example.cs
trackler-2.2.1.142 tracks/csharp/exercises/word-count/Example.cs
trackler-2.2.1.141 tracks/csharp/exercises/word-count/Example.cs
trackler-2.2.1.140 tracks/csharp/exercises/word-count/Example.cs
trackler-2.2.1.139 tracks/csharp/exercises/word-count/Example.cs
trackler-2.2.1.138 tracks/csharp/exercises/word-count/Example.cs
trackler-2.2.1.137 tracks/csharp/exercises/word-count/Example.cs
trackler-2.2.1.136 tracks/csharp/exercises/word-count/Example.cs
trackler-2.2.1.135 tracks/csharp/exercises/word-count/Example.cs
trackler-2.2.1.134 tracks/csharp/exercises/word-count/Example.cs
trackler-2.2.1.133 tracks/csharp/exercises/word-count/Example.cs
trackler-2.2.1.132 tracks/csharp/exercises/word-count/Example.cs