C# Program to find number of occurrence of a character in a String
- By using following example,It is possible to count each character is occurred how many times in the given string.
class NumberOfCharectersCount
{
public static void Main(string[] args)
{
string input = "csharpstar";
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();
}
}
No comments