Saturday, 14 September 2013

Count vowels, consonsants, digits, and other char in a entered string of text

Count vowels, consonsants, digits, and other char in a entered string of text

Can someone please look at my code? I need to count the characters and
have them display in the correct label box. I did have the digit one
working and them messed it up working on the vowels. I am so frustrated.
Thanks, Tish
int consCount = 0;
int vowelCount = 0;
int digitCount = 0;
int otherCount = 0;
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();
this.constdisplayLabel.Text = consCount.ToString();

No comments:

Post a Comment