【发布时间】:2009-07-28 12:04:21
【问题描述】:
我想知道当您在文本框中键入句子时,在计算元音时使用了哪些事件/事件。
我不太确定这是否与“KeyPress”或“KeyUp”有关。
感谢您的帮助。
=====
这就是我现在卡住的地方:
private void btnCount_Click(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.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");
private void textBox1_KeyDown(object sender, EventArgs e)
{
string yourSentence;
yourSentence = textBox1.Text.ToLower().Trim();
//I think I have to add the codings here. But what will happened to the
//btnCount_Click?
}
【问题讨论】:
-
您是在尝试自己执行此操作,还是在谈论执行此操作的特定应用程序?
-
我正在尝试自己做。我使用 switch 语句编写了一个代码,它计算元音并在列表框中显示元音的数量。现在我想尝试一些新的东西,比如如果我写句子它会识别元音并显示有多少元音在写作。
-
注意,因为有人可以选择大部分文本并覆盖它。
-
您好,请检查我对 cmets 的编辑,了解您的代码!