I'm wondering what event/events is/are being used in counting the vowels while you're typing the sentence in the textbox.
I'm not quite sure if it's something to do with "KeyPress
" or "KeyUp
".
I would appreciate your help.
=====
This is now where I'm stucked:
private void textBox1_TextChanged(object sender, EventArgs e)
{
string yourSentence;
yourSentence = textBox1.Text.ToLower().Trim();
char ch1 = 'a';
char ch2 = 'e';
char ch3 = 'i';
char ch4 = 'o';
char ch5 = 'u';
int counta = 0;
int counte = 0;
int counti = 0;
int counto = 0;
int countu = 0;
int j = counta + counte + counti + counto + countu;
foreach (char v in yourSentence)
{
if (v == ch1) { counta++; j++; }
else if (v == ch2) { counte++; j++; }
else if (v == ch3) { counti++; j++; }
else if (v == ch4) { counto++; j++; }
else if (v == ch5) { countu++; j++; }
}
listBox1.Items.Clear();
listBox1.Items.Add("There are " + counta.ToString().Trim() + " a's in the sentence");
listBox1.Items.Add("There are " + counte.ToString().Trim() + " e's in the sentence");
listBox1.Items.Add("There are " + counti.ToString().Trim() + " i's in the sentence");
listBox1.Items.Add("There are " + counto.ToString().Trim() + " o's in the sentence");
listBox1.Items.Add("There are " + countu.ToString().Trim() + " u's in the sentence");
listBox1.Items.Add("All in all there are " + j.ToString().Trim() + " vowels in the sentence");
This is working perfectly. Thanks :-)