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

Java Final keyword

Introduction : java final keyword The final keyword present in Java programming language is generally used for restricting the user. …

Read more

C++ Memory Management: new and delete

C++ Memory Management We know that arrays store contiguous and the same type of memory blocks, so memory is allocated …

Read more