using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string str;
int x = 0, i = 0;
str = textBox1.Text;
if (str.Length > 0)
{
for (; i < str.Length-1; i++)
{
if (str[i].ToString() == " ")
{
if (str[i + 1].ToString() != " ") x++;
else if (str[i + 1] == str.Length && str[i + 1].ToString() != " ") x++;
}
}
if (str[0].ToString() != " ") x++;
}
textBox2.Text = x.ToString();
}
}
}