Answer the question
In order to leave comments, you need to log in
How can I change the Windows forms code so that it counts the number of letters in each word?
private void button1_Click(object sender, EventArgs e)
{
int index = listBox.SelectedIndex;
string rts = (string)listBox1.Items[index];
int len = str.Length;
int count = 0;
int i = 0;
while(i < len)
{
if (str[i] == " ")
count++;
i++;
}
Label1.text = "Количество пробелов = " +
count.ToString();
}
Answer the question
In order to leave comments, you need to log in
I understand that you need to count certain letters.
The correct option is to use RegEx
Well, if you do it on the forehead as it is written in the condition, then:
string input = "Раз два три четыре пять, я иду искать";
string[] words = input.Split(new char[] { ' ', ',', '.', '-', '!', '?' }, StringSplitOptions.RemoveEmptyEntries);
foreach(var word in words) { Console.WriteLine($"{word}: длина {word.Length}"); }
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question