Загрузка данных


// button2 — количество точек и запятых
private void button2_Click(object sender, EventArgs e)
{
    listBox1.Items.Clear();

    string s = textBox1.Text;

    int dots = 0;
    int commas = 0;

    for (int i = 0; i < s.Length; i++)
    {
        if (s[i] == '.')
            dots++;

        if (s[i] == ',')
            commas++;
    }

    listBox1.Items.Add("Точек: " + dots);
    listBox1.Items.Add("Запятых: " + commas);
}

// button3 — количество слов
private void button3_Click(object sender, EventArgs e)
{
    listBox1.Items.Clear();

    string s = textBox1.Text;

    string[] words = s.Split(' ');

    int count = 0;

    for (int i = 0; i < words.Length; i++)
    {
        if (words[i] != "")
            count++;
    }

    listBox1.Items.Add("Количество слов: " + count);
}

// button4 — самый часто встречающийся символ
private void button4_Click(object sender, EventArgs e)
{
    listBox1.Items.Clear();

    string s = textBox1.Text;

    char maxChar = ' ';
    int maxCount = 0;

    for (int i = 0; i < s.Length; i++)
    {
        int count = 0;

        for (int j = 0; j < s.Length; j++)
        {
            if (s[i] == s[j])
                count++;
        }

        if (count > maxCount)
        {
            maxCount = count;
            maxChar = s[i];
        }
    }

    listBox1.Items.Add("Символ: " + maxChar);
    listBox1.Items.Add("Количество: " + maxCount);
}

// button5 — вывести цифры
private void button5_Click(object sender, EventArgs e)
{
    listBox1.Items.Clear();

    string s = textBox1.Text;

    string result = "";

    for (int i = 0; i < s.Length; i++)
    {
        if (Char.IsDigit(s[i]))
            result += s[i] + " ";
    }

    listBox1.Items.Add(result);
}

// button6 — длины слов
private void button6_Click(object sender, EventArgs e)
{
    listBox1.Items.Clear();

    string s = textBox1.Text;

    string[] words = s.Split(' ');

    string result = "";

    for (int i = 0; i < words.Length; i++)
    {
        if (words[i] != "")
            result += words[i].Length + " ";
    }

    listBox1.Items.Add(result);
}