Mega Code Archive

 
Categories / C# / Development Class
 

Use regular expression to replace chars

using System; using System.Text.RegularExpressions; class RegexSubstitution {    public static void Main()    {       string testString1 = " stars *****";       Regex testRegex1 = new Regex( @"\d" );       Console.WriteLine( "Original string: " + testString1 );       testString1 = Regex.Replace( testString1, @"\*", "^" );       Console.WriteLine( "^ substituted for *: " + testString1 );           } }