replaces extra white space - CSharp Language Basics

CSharp examples for Language Basics:Regex

Description

replaces extra white space

using System;
using System.Text.RegularExpressions;

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);
      }
}

Related Tutorials