前端之家收集整理的这篇文章主要介绍了
将多个空格换成一个空格(正则表达式),
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
- usingSystem;
- usingSystem.Text.RegularExpressions;
- publicclassExample
- {
- staticvoidMain()
- try
- stringinput="Thisistextwithfartoomuch"+"whitespace.";
- stringpattern="\\s+";
- stringreplacement="";
- Regexrgx=newRegex(pattern);
- stringresult=rgx.Replace(input,replacement);
- Console.WriteLine("OriginalString:{0}",input);
- "ReplacementString:{0}",result);
- Console.Read();
- }
- catch(Exception)
- {
- throw;
- }
- }
原文链接:https://www.f2er.com/regex/357624.html