How to count a number of vowels and consonants in a String?


How to count a number of vowels and consonants in a String?

   public String CountVowel(String x)
        {
            x = x.ToLower();
            char[] arr = x.ToCharArray();
            int leng = arr.Length;
            foreach (char ch in arr)
            {
                if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
                {
                    count++;
                }
              
            }
            Console.WriteLine("Total Constant " + (leng - count));
            return count.ToString();
          
        }
        static void Main(string[] args)
        {
            Program p1 = new Program();
      Console.WriteLine("How to count a number of vowels and consonants in a String?");

            Console.WriteLine("Total vowel "+ p1.CountVowel("shivKumar"));
            Console.ReadLine();
}

        





Share:

No comments:

Post a Comment

Popular

Tags

Mobile

Recent Posts