Hi,
I want to write a program to parse a word entered in a textbox by a user at runtime.
The output should display the number of times each alphabet appeared in the word. Can Someone give me a clue how to go about it???
Thanks
Hi,
I want to write a program to parse a word entered in a textbox by a user at runtime.
The output should display the number of times each alphabet appeared in the word. Can Someone give me a clue how to go about it???
Thanks
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
AlanRank #669 · 3.6K reputationPosted Sep 16, 2008, 2:57 PM EDT
Something like this perhaps:
int[] numLetters = new int[26];
string temp = textBox1.Text.ToUpper();
for(int i = 0; i < temp.Length; i++)
{
char c = temp[i];
int alpha = (int)c - 65; // A is 65
Console.WriteLine(alpha);
numLetters[alpha]++;
}
string result = textBox1.Text + " contains the following letters \r\n";
for (int i = 0; i < 26; i++)
{
if (numLetters[i] > 0)
{
result += "\r\n " + (char)(i + 65) + " x " + numLetters[i];
}
}
MessageBox.Show(result);