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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Jun 10, 2015, 9:25 PM EDT
Manoj BhoirRank #599 · 4K reputationPosted Jun 10, 2015, 9:04 PM EDT
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
Sabyasachi MishraRank #889 · 2.4K reputationPosted Jun 10, 2015, 9:06 PM EDT
Saroj Kumar SahuRank #1,766 · 849 reputationPosted Jun 10, 2015, 9:09 PM EDT