Tech Study

Write a C# program to count a total number of alphabets, digits and special characters in a string

Introduction

we have brief in this article about multiple methods to find the total number of alphabets,digits and strings in c programming

we have used Visual Studio 2012 for debugging purpose. But you can use any version of visual studio as per your availability..

using System;
public class String Exercise
{
    public static void Main()
    {
        string str;
        int alphabet, digit, special char, i, l;
        alphabet = digit = special char = i = 0;
 
        Console.Write("Enter the string : ");
        str = Console.ReadLine();
        l = str.Length;
 
        while (i < l)
        {
            if ((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z'))
            {
                alphabet++;
            }
            else if (str[i] >= '0' && str[i] <= '9')
            {
                digit++;
            }
            else
            {
                specialchar++;
            }
 
            i++;
        }
 
        Console.Write("Number of Alphabets in the string is : {0}\n", alphabet);
        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", specialchar);
 
        Console.ReadLine();
    }
}

Result

Write a C# program to count a total number of alphabets, digits and special characters in a string
Write a C# program to count a total number of alphabets, digits and special characters in a string

Taggeddigits and special characters in a stringWrite a C# program to count a total number of alphabets

Python Examples

Introduction: Python Examples are the basic programming concepts of python like python syntax,python data types,,python operators,python if else,python comments etc.. …

Read more

C String Functions

C String Functions perform certain operations, It provides many useful string functions which can come into action. The <string.h> header …

Read more