扔块砖头
string str1 = " 1 2 3 4 ";
int iCount = str1.Length;
string str2 = str1.Substring(0,1);
for(int i = 1;i<iCount;i++)
{
if(str1.Substring(i,1) == " " && str1.Substring(i-1,1) == " ")
{
}
else
{
str2 = str2 + str1.Substring(i,1);
}
}
string str1 = " 1 2 3 4 ";
int iCount = str1.Length;
string str2 = str1.Substring(0,1);
for(int i = 1;i<iCount;i++)
{
if(str1.Substring(i,1) == " " && str1.Substring(i-1,1) == " ")
{
}
else
{
str2 = str2 + str1.Substring(i,1);
}
}
Regex x = new Regex(@"\s+");
string b = x.Replace(a," ");//b="1 2,1,2 3,3, 3,3,3"
using System.Text.RegularExpressions;
string a = " 1 2 3 4 ";
a =new System.Text.RegularExpressions.Regex("[\\s]+").Replace(a," ");