Created
September 19, 2012 09:10
-
-
Save ramjill/3748612 to your computer and use it in GitHub Desktop.
Given an input string (of no more than 300 characters in length), parse the string and count the occurrences of vowels and consonants. The data should be output in the format below. Punctuation should be ignored. {vowels:<count>,consonants:<count>} eg:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Challenge | |
{ | |
public static void Main() | |
{ | |
Console.WriteLine("Enter String Name"); | |
string inputString = Console.ReadLine(); | |
string alphabet = new String(inputString.Where(Char.IsLetter).ToArray()); | |
int vowel = CountVowels(alphabet); | |
int consonants = CountConsonants(alphabet); | |
Console.WriteLine("{0}vowels:{1},consonants:{2}{3}", "{", vowel, consonants, "}"); | |
Console.Read(); | |
} | |
public static int CountVowels(string value) | |
{ | |
const string vowels = "aeiou"; | |
return value.Count(chr => vowels.Contains(char.ToLowerInvariant(chr))); | |
} | |
public static int CountConsonants(string value) | |
{ | |
const string vowels = "aeiou"; | |
return value.Count(chr => !vowels.Contains(char.ToLowerInvariant(chr))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment