将多个空格换成一个空格(正则表达式)

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

猜你在找的正则表达式相关文章