Javascript/C# Word Count

A function to count the number of words in Javascript:

function CountWords(w){
    var fc = w.split(" ");
    return fc.length;
}

Simple as it is, I’ve been asked for it a million times…

In C#, it’s equally simple:

public int CountWords(string ToCount)
{
    return ToCount.Split(' ').Length;
}

1 Comment

Sanat GersappaJuly 27th, 2005 at 2:50 pm

TMTOWTDI

function CountWords(w)
{
var a = w.match(/\w+/g);
return a.length;
}

Leave a comment

Your comment