Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have created a C# Windows Form App that allows the user to type in a word in a textbox and it will count and

I have created a C# Windows Form App that allows the user to type in a word in a textbox and it will count and display how many consonants and vowels are in that word. I would like to change the app so that instead of reading a word from a textbox, I want it to read one or more words from a ListBox and count and display how many vowels and consonants are present.

Below is the C# code that I have currently. How can I change it so that it reads words from ListBox, not a TextBox.

private void button1_Click(object sender, EventArgs e)

{

string str = txtString.Text;

txtVowels.Text = CountVowels(str);

txtConsonants.Text = CountConsonants(str);

}

private string CountConsonants(string str)

{

int consonantsCount = 0;

foreach (char ch in str)

{

if (char.IsLetter(ch))

{

switch (char.ToUpper(ch))

{

case 'A':

case 'E':

case 'I':

case 'O':

case 'U':

break;

default:

consonantsCount++;

break;

}

}

}

return consonantsCount.ToString();

}

private string CountVowels(string str)

{

int vowelsCount = 0;

foreach (char ch in str)

{

if (char.IsLetter(ch))

{

switch (char.ToUpper(ch))

{

case 'A':

case 'E':

case 'I':

case 'O':

case 'U':

vowelsCount++;

break;

}

}

}

return vowelsCount.ToString();

}

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions

Question

What are the major social responsibilities of business managers ?

Answered: 1 week ago

Question

What are the skills of management ?

Answered: 1 week ago

Question

Provide examples of Dimensional Tables.

Answered: 1 week ago