Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
765 B
1
Indexable
Never
string str;

 int alp, digit, splch, i, l;

 alp = digit = splch = i = 0;
 Console.WriteLine("Count total number of alphabets, digits & special characters :\n");
 Console.WriteLine("--------------------------------------------------\n");
 Console.WriteLine("Enter a string : ");
 str = Console.ReadLine();
 l = str.Length;
 while (i < l)
 {
 if ((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z'))
 {
 alp++;
 }
 else if (str[i] >= '0' && str[i] <= '9')
 {
 digit++;
 }
 else
 {
 splch++;
 }
 i++;
 }
 Console.Write("Number of Alphabets in the string is : {0}\n", alp);
 Console.Write("Number of Digits in the string is : {0}\n", digit);
 Console.Write("Number of Special characters in the string is : {0}\n\n", splch);
Leave a Comment