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


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 static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace WindowsFormsApp6
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int index = listBox1.SelectedIndex;
            string str = (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();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string s = listBox2.SelectedItem.ToString();
            int zero = 0;
            int one = 0;

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

                if (s[i] == '1')
                    one++;
            }

            label2.Text = "Количество нулей: = " + zero;
            label2.Text = "Количество единиц: = " + one;

        }
    }
}