Showing posts with label Program to find occurrence of character in string. Show all posts
Showing posts with label Program to find occurrence of character in string. Show all posts

Monday, 5 October 2020

Program to find occurrence of character in string

 Program to find occurrence of character in string

Step 1: Open Visual Studio and select console application.

Step 2: Write a Program to find occurrence of character in string

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace CharacterOccurrenceApp
{
    class Program
    {
        static void Main(string[] args)
        {
            string Statement = string.Empty;
 
            Console.WriteLine("Enter a string to check occurrence of a character numbers");
 
            Statement = Console.ReadLine();
            Statement = Statement.ToLower();
 
            if (Statement.Length > 0)
            {
                while (Statement.Length > 0)
                {
                    int CountCharacter = 0;
                    Console.Write("Number of Occurance of '" + Statement[0] + "': ");
                   
                    //Checking the Character occurrence in the string entered by the user
                    for (int i = 0; i < Statement.Length; i++)
                    {
                        if (Statement[0] == Statement[i])
                        {
                            CountCharacter++;
                        }
                    }
 
                    //Count of each character
                    Console.Write(CountCharacter + "\n");
 
                    //Removing that character from the string
                    Statement = Statement.Replace(Statement[0].ToString(), string.Empty);
                }
            }
            Console.ReadLine();
        }
    }
}












Run the application and enter the string value then press "Enter" key then see the output.


Factorial of a Number

Recently Viewed