日期:2014-05-17 浏览次数:21445 次
//原始字符串
string s="a b c d f g";
//想得到的结果
string s="a b c d f g";
string source = "a b c d f g";
string patten = @"(?is)(?<=[\s])[\s]+";
Regex reg = new Regex(patten);
source = reg.Replace(source, "");
Str= Regex.Replace(Str.Trim(), "\\s+", " ");
string s = "a b c d f g";
s = string.Join(" ", s.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries));
//原始字符串
string s="a b c d f g";
s = s.Trim();
string resString = "";
for(int i = 1 ; i < s.Length;i++){
if(s[i]==" "&& s[i-1]=="")continue;
resString+=s[i].ToString();
}
s=resString;
string.Join(" ", s.split(new char[]{' '},StringSplitOptions.RemoveEmptyEntries));