Tuesday, May 1, 2012

The Old Count Letters with Regex example

static void RegexMatchesComplex(string str)
{            
         char[] letters = str.ToCharArray().Distinct().ToArray();
         foreach (char c in letters)            
        {
              Regex regex = new Regex(c.ToString());                
              Console.WriteLine(c.ToString() + " " + regex.Matches(str).Count);            
         }        
}

No comments:

Post a Comment