Count and Print the alphabets having ASCII value in the range [ l , r ] | C # implementation of the above approach ; Function to count the number of characters whose ascii value is in range [ l , r ] ; Initializing the count to 0 ; Increment the count if the value is less ; return the count ; Driver code
using System ; class GFG { static int CountCharacters ( string str , int l , int r ) { int cnt = 0 ; int len = str . Length ; for ( int i = 0 ; i < len ; i ++ ) { if ( l <= str [ i ] && str [ i ] <= r ) { cnt ++ ; Console . Write ( str [ i ] + " ▁ " ) ; } } return cnt ; } public static void Main ( ) { string str = " geeksforgeeks " ; int l = 102 , r = 111 ; Console . Write ( " Characters ▁ with ▁ ASCII ▁ values " + " ▁ in ▁ the ▁ range ▁ [ l , ▁ r ] ▁ are ▁ STRNEWLINE " ) ; Console . Write ( " and count is " CountCharacters ( str , l , r ) ) ; } }