本文介绍了c#确定文本是辅音,元音,数字还是其他字符。然后它显示每个的计数。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法让代码计入输入文本框中的元音。我做错了什么?
I cannot get me code count the vowels in the entry text box. What have I done wrong?
string inputString;
inputString = this.entryTextBox.Text.ToLower();
char[] vowels = new char[] {'a', 'e', 'i', 'o', 'u'};
string vow = new string(vowels);
for (int index = 0; index < inputString.Length; index++)
{
if (char.IsLetterOrDigit(inputString[index]))
{
if (inputString.Contains(vow))
vowelCount++;
}
else if (char.IsDigit(inputString[index]))
digitCount++;
}
this.voweldisplayLabel.Text = vowelCount.ToString();
this.digitsdisplayLabel.Text = digitCount.ToString();
推荐答案
if (System.Array.IndexOf(vowels, inputString[index]) >= 0)
++vowelCount;
string inputString;
inputString = this.entryTextBox.Text.ToLower();
char[] vowels = {'a', 'e', 'i', 'o', 'u'};
string vow;
int vowelCount = 0;
int digitCount = 0;
for int j = 0; j < 6; j++)
{
vow = vow + vowels[j];
}
for (int index = 0; index < inputString.Length; index++)
{
if (char.IsLetterOrDigit(inputString[index]))
{
if (inputString.Contains(vow))
vowelCount++;
}
else if (char.IsDigit(inputString[index]))
digitCount++;
}
this.voweldisplayLabel.Text = vowelCount.ToString();
this.digitsdisplayLabel.Text = digitCount.ToString();
所以你有,你的代码,翻新......或类似的......
So there you are, your code, refurbished ... or something like that ...
这篇关于c#确定文本是辅音,元音,数字还是其他字符。然后它显示每个的计数。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!