What is the C# coding needed to take the words that I have opened up and are now
ID: 3858992 • Letter: W
Question
What is the C# coding needed to take the words that I have opened up and are now shown in my ListBox and display how many vowels and consonants are in each word?
Below is the coding that I have so far and now I am stuck (I cannot figure out how to read what is in my ListBox and decide how many consonants and how many vowels are in the words)
* C # Windows Form
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace quest4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string fileName;
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.ShowDialog();
string filePath = openFileDialog.FileName;
StreamReader inputFile = new StreamReader(filePath);
listBox1.Items.Clear();
while (!inputFile.EndOfStream)
{
fileName = inputFile.ReadLine();
listBox1.Items.Add(fileName);
}
}
Form1Designer.cs Form1.cs Form1.cs IDesignr × Form1 Opened File Will Be Displayed Below in istBox1 The Number of Vawels Found in List Bcx 1 was The Number of Consonants Found in List Box 1 was: Press this button to open file: button1Explanation / Answer
As per my concern you don't need to read list box items. When you open file you are pushing items. So at that time process file name and store count vowels and consonants.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace quest4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int vowels = 0, consonants = 0;
private void button1_Click(object sender, EventArgs e)
{
string fileName;
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.ShowDialog();
string filePath = openFileDialog.FileName;
StreamReader inputFile = new StreamReader(filePath);
listBox1.Items.Clear();
while (!inputFile.EndOfStream)
{
fileName = inputFile.ReadLine();
listBox1.Items.Add(fileName);
// counting vowels and consonants
for (int i = 0; i < fileName.Length; i++)
{
if (fileName[i] == 'a' || fileName[i] == 'e' || fileName[i] == 'i' || fileName[i] == 'o' || fileName[i] == 'u')
{
vowels++;
}
else if (!char.IsWhiteSpace(fileName[i]))
{
consonants++;
}
}
}
}
}
}
-------------------------------------------------------------------------------------------------------------------------------------------------
now on evry word loading we are counting vowels and consonants. So then we can set this count in respoctive boxes. No need to pop out saved words in list box again.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.