Below program is for get total count of alphabets,digits and special char from given string.
Hope it will be useful for you.
class Program
{
static void Main(string[] args)
{
string s = "";
int alphacount = 0, digitcount = 0, specialcount = 0;
Console.WriteLine("Enter string");
s = Console.ReadLine();
foreach (int i in s)
{
if ((i >= 65 && i <= 90) || (i >= 97 && i <= 122))
alphacount++;
else if (i >= 48 && i <= 57)
digitcount++;
else
specialcount++;
}
Console.WriteLine("Total no of Alphabets:"+""+ alphacount);
Console.WriteLine("Total no of Digits:" + "" + digitcount);
Console.WriteLine("Total no of Specialchar:" + "" + specialcount);
Console.ReadLine();
}
}
For ex input:goswami himanshu15@gmail.com :
Output:Total no of Alphabets:23
Total no of Digits:2
Total no of Specialchar:3
No comments:
Post a Comment
Please let me know if you have any feedback or doubts.