Count each character occurrence in a given string
Can u tell me how to count each character occurrence in a given string?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Upendra Pratap ShahiPosted Jun 11, 2015, 1:25 AM
Saroj Kumar SahuPosted Jun 11, 2015, 1:09 AM
Sabyasachi MishraPosted Jun 11, 2015, 1:06 AM
Manoj BhoirPosted Jun 11, 2015, 1:04 AM
inputString = inputString.Replace(" ", "");
char[] uniqueChars = inputString.Distinct().ToArray();
foreach (char uniquechar in uniqueChars)
{
int stringCount = inputString.Replace(uniquechar.ToString(), "").Length;
Console.WriteLine("Count Of " + uniquechar + " in " + inputString + " is " + (inputString.Length - stringCount).ToString());
}
Count Of o in sowmyavelaga is 1
Count Of w in sowmyavelaga is 1
Count Of m in sowmyavelaga is 1
Count Of y in sowmyavelaga is 1
Count Of a in sowmyavelaga is 3
Count Of v in sowmyavelaga is 1
Count Of e in sowmyavelaga is 1
Count Of l in sowmyavelaga is 1
Count Of g in sowmyavelaga is 1