C#使用正则表达式去除字符串中的多个不同大小的空格
字符串str:“ 1.0 11 0.0 4”
处理:
string str = " 1.0 11 0.0 4";
string trim = Regex.Replace(str, "\\s{2,}", ",");
string trim = Regex.Replace(str, "\\s{2,}", ",");
结果trim:“,1.0,11,0.0,4”
或:
Regex replaceSpace = new Regex(@"\s{1,}", RegexOptions.IgnoreCase);
return replaceSpace.Replace(strWords, ",").Trim();
return replaceSpace.Replace(strWords, ",").Trim();