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.
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.
AlanPosted Sep 16, 2008, 6:57 PM
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);