In this blog I shall demonstrate the number of occurrences of a character in a string.
I hope this article remember our school days programming.
Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SchoolDays
{
class Program
{
static void Main(string[] args)
{
string input = "WWW.C-SHARPCORNER.COM";
while (input.Length > 0)
{
Console.Write(input[0] + " : ");
int count = 0;
for (int j = 0; j < input.Length; j++)
{
if (input[0] == input[j])
{
count++;
}
}
Console.WriteLine(count);
input = input.Replace(input[0].ToString(),string.Empty);
}
Console.ReadLine();
}
}
}
Each time a character count is found then that character is removed from the string for the next iteration.

Karunakar BhogyariPosted Aug 27, 2018, 6:02 AM
You are savior of the day...
vivek kumarPosted Jun 4, 2018, 7:13 AM
Very useful
Upendra Pratap ShahiPosted Jun 11, 2015, 3:44 AM
nice sir..
Nitish SainiPosted Feb 13, 2015, 4:00 AM
How can i use each count in array.
Praveen Raveendran PillaiPosted Nov 21, 2014, 4:14 AM
Michael, I know that this source code is not a performace oriented one. Using various libraries available in .Net framework you can achieve the same result with very few lines of code too. My intention was to demsonstrate how we used to code such logic during school days and that too without using any of the newly added libararies from Microsoft .Net Framework.
Michael OSheaPosted Nov 2, 2014, 3:30 PM
This is absolutely horrid code.Note too you aren't removing a character from a string, but creating a new string for each iteration of the loop. This will play hell on garbage collection. I have posted an example of something more efficient and clear, see https://twitter.com/MichaelDOShea/status/529005571832573952
Udaya kumarPosted Oct 24, 2014, 10:50 AM
Good logic
Anil Kumar MurmuPosted Jun 10, 2014, 1:45 AM
good one.