Count and Print the alphabets having ASCII value not in the range [ l , r ] | C # implementation of the above approach ; Function to count the number of characters whose ascii value not in range [ l , r ] ; Initializing the count to 0 ; using map to print a character only once ; Increment the count if the value is less ; return the count ; Driver code
using System ; using System . Collections ; using System . Collections . Generic ; class GFG { static int CountCharacters ( string str , int l , int r ) { int cnt = 0 ; Dictionary < char , int > m = new Dictionary < char , int > ( ) ; int len = str . Length ; for ( int i = 0 ; i < len ; i ++ ) { if ( ! ( l <= str [ i ] && str [ i ] <= r ) ) { cnt ++ ; if ( ! m . ContainsKey ( str [ i ] ) ) { m [ str [ i ] ] = 0 ; Console . Write ( str [ i ] + " ▁ " ) ; } m [ str [ i ] ] ++ ; } } return cnt ; } public static void Main ( string [ ] args ) { string str = " geeksforgeeks " ; int l = 102 , r = 111 ; Console . Write ( " Characters ▁ with ▁ ASCII ▁ values " + " not ▁ in ▁ the ▁ range ▁ [ l , ▁ r ] ▁ STRNEWLINE in " + " the ▁ given ▁ string ▁ are : ▁ " ) ; Console . WriteLine ( " and count is " CountCharacters ( str , l , r ) ) ; } }