words = 0; if (Ln.Length > 0) { while (Ln.IndexOf(' ') != -1) { words = words + 1; Ln = Ln.Substring(0, Ln.IndexOf(' ')); MessageBox.Show(Ln + words.ToString()); } }