Dan*_*olo 18
string new_string = Regex.Replace(orig_string, @"\s", "") 将删除所有空格
string new_string = Regex.Replace(orig_string, @"\s+", " ") 只会将多个空格合并为一个空格
Tim*_*ker 15
我假设你想要
如果这是正确的,那么你可以使用
resultString = Regex.Replace(subjectString, @"( |\r?\n)\1+", "$1");
Run Code Online (Sandbox Code Playgroud)
这样可以保持原始的"类型"空白不变,并且还可以正确保留Windows行结尾.如果您还想将多个标签"压缩"为一个,请使用
resultString = Regex.Replace(subjectString, @"( |\t|\r?\n)\1+", "$1");
Run Code Online (Sandbox Code Playgroud)
要将一串换行符和空格(每个的任意数量)压缩到一个换行符中,请使用
resultString = Regex.Replace(subjectString, @"(?:(?:\r?\n)+ +){2,}", @"\n");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14840 次 |
| 最近记录: |