Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

In C#, the string object has some convenience in it:

  return inputString.Count( "eaoiuAIEOU".Contains );
Or if you want to solve two problems:

  static Regex VowelMatcher = new Regex( "[aeiou]",
    RegexOptions.Compiled | RegexOptions.IgnoreCase );
  ...
  return VowelMatcher.Matches( inputString ).Count;
And if you want to be clever and snarky:

  return 2; // number of vowels in "a string"


The Count and Contains methods are not on string, they're both extension methods on IEnumerable<T>, which string gets for free by implementing IEnumerable<char>.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: