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" <firstname.lastname@example.org> 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.
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL