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

前端之家收集整理的这篇文章主要介绍了将多个空格换成一个空格(正则表达式)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_404_1@
  • 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;
  • }
  • }
  • 猜你在找的正则表达式相关文章