加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 06:37:47 所属栏目:百科 来源:网络整理
导读:using System; using System.Text.RegularExpressions; public class Example { static void Main() try string input= "Thisistextwithfartoomuch" + "whitespace." ; string pattern= "s+" ; string replacement= "" ; Regexrgx= new Regex(pattern); st
  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. }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读