C#正则表达式示例3

using System;using System.Text.RegularExpressions;namespace RegExApplication {class Program {static void Main(string[] args) {

编程学习网为您整理以下代码实例,主要实现:C#正则表达式示例3,希望可以帮到各位朋友。

using System;
using System.Text.RegularExpressions;

namespace RegExApplication {

   class Program {

      static voID Main(string[] args) {
         string input = "Hello   World   ";
         string pattern = "\s+";
         string replacement = " ";
         Regex rgx = new Regex(pattern);
         string result = rgx.Replace(input, replacement);

         Console.Writeline("Original String: {0}", input);
         Console.Writeline("Replacement String: {0}", result);    
         Console.ReadKey();
      }
   }
}

本文标题为:C#正则表达式示例3

基础教程推荐