Word count


using System;
using System.Text.RegularExpressions;

class Program
{
    static void Main(string[] args)
    {

         string r = @"\b(\w|[-'])+\b"; 
    
         string text = "This is a test"; 
         Console.WriteLine (Regex.Matches (text, r).Count);            
    }
}

The output:


4
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.