Introduction

In this blog we create a c# program which take string as an input, and then we give output as how many characters are in that string, how many characters are letters, how many characters are digit and how many characters are is special character like symbol, space etc.


Count total letters, digits and special characters from string in c# - YogeshHadiya.in


 

Code






Output 


Count total letters, digits and special characters from string - YogeshHadiya.in




Explanation

  • Here first we get input from user.
  • Then define some integer variable which we used as a counter.
  • Then we convert input string as a char array by ToCharArray() method.
  • Then iterate for each loop on char array
    • In this loop we check character is letter or digit by char.IsLetter() and char.IsDigit() method and increment in our counter variable.
    • And for special character we use char.IsLetterOrDigit() method this method return true if character is digit or letter and false if not. We increment our counter variable if condition is false.