Try Code Live

Count Vowels in a string


using System;

class Program
{
    static void Main()
    {
        string input = "hello world";
        int vowels = 0, consonants = 0;
        string vowelChars = "aeiouAEIOU";

        foreach (char c in input)
        {
            if (Char.IsLetter(c))
            {
                if (vowelChars.Contains(c))
                    vowels++;
                else
                    consonants++;
            }
        }

        Console.WriteLine($"Vowels: {vowels}, Consonants: {consonants}");
    }
}


Vowels: 3, Consonants: 7