If you need to trim string and remove extra spaces from the middle of the string
you can use this simple sample:
string s = TextBox1.Text;
s = s.Trim(); // trim left and right spaces
while (s.IndexOf(" ") != -1) // it is 2 spaces in the quotes!!
{
s = s.Remove(s.IndexOf(" "), 1); // remove extra spaces in the middle of the string
}
Label1.Text = s;
It will take any input string from the TextBox1, i.e. like this:
"___aaa_______bbb_________ccc_ddd__eee_",
where "_" is a space symbol, and trim it to the:
"aaa_bbb_ccc_ddd_eee".
All our simple samples available as Microsoft Visual Studio 2008 website projects.
You can DOWNLOAD this String trim sample project from Rapidshare.