Re: word count!!! Faster, Leaner, Meaner!
Here's a even shorter method, which is probably a little more efficient with
resources, and definitely more accurate.
1. Use a regular expression match groups of non-whitespace characters.
2. Count the number of matches.
This has the advantage of dealing with repeated spaces and the varying forms
static void Main(string  args)
string Test = "Count words in this string.";
string Pattern = @"\S+";
MatchCollection Words = Regex.Matches(Test, Pattern);
Console.WriteLine("Word count is " + Words.Count);
"Russell Jones" <email@example.com> wrote:
>Here's a shorter method.
>1. Read the file into a string
>2. Split the resulting string using a space as a delimiter. That returns
>array of strings.
>3. Count the number of items in the array.
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center