Hi, Below program is for getting number of occurrence from a given string.
class Program
{
static void Main(string[] args)
{
Console.Write("Enter String: ");
string input = Console.ReadLine();
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); //Remove matched character
}
Console.ReadLine();
}
}
Output:
Enter String: csharpprogram
c : 1
s : 1
h : 1
a : 2
r : 3
p : 2
o : 1
g : 1
m : 1
No comments:
Post a Comment
Please let me know if you have any feedback or doubts.