Count consonants in a string ( Iterative and recursive methods ) | Iterative C # program to count total number of consonants ; Function to check for consonant ; To handle lower case ; To check is character is Consonant ; Driver code
using System ; class GFG { static bool isConsonant ( char ch ) { ch = Char . ToUpper ( ch ) ; return ! ( ch == ' A ' ch == ' E ' ch == ' I ' ch == ' O ' ch == ' U ' ) && ch >= 65 && ch <= 90 ; } static int totalConsonants ( String str ) { int count = 0 ; for ( int i = 0 ; i < str . Length ; i ++ ) if ( isConsonant ( str [ i ] ) ) ++ count ; return count ; } public static void Main ( ) { String str = " abc ▁ de " ; Console . Write ( totalConsonants ( str ) ) ; } }