Remove extra spaces between two words by doing one click on the button in C#.NET.

In this article we will see how to remove extra spaces between two words by doing one click on the button in C#.NET.

Let's see one example :

using System.Windows.Forms;

namespace getsolutionhubDemo
{
    public partial class removeExtraSpaces : Form
    {
        public removeExtraSpaces()
        {
            InitializeComponent();
        }

        private void rmSpace_Click(object sender, System.EventArgs e)
        {
            int strLen = txtBox.Text.Length;
            for (int i = 0; i <= strLen; i++)
            {
                string rm = txtBox.Text.Replace("  ", " ");
                txtBox.Text = rm;
            }
        }
    }
}

Output: