replace every '*' with a '^' and display the result - CSharp Language Basics

CSharp examples for Language Basics:Regex

Description

replace every '*' with a '^' and display the result

Demo Code

using System;/*www . j ava 2 s. c  o  m*/
using System.Text.RegularExpressions;
class MainClass
{
   static void Main( string[] args )
   {
      string testString1 = "This sentence ends in 5 stars *****";
      Console.WriteLine( "First test string: {0}", testString1 );
      // replace every '*' with a '^' and display the result
      testString1 = Regex.Replace( testString1, @"\*", "^" );
      Console.WriteLine( "^ substituted for *: {0}", testString1 );
   }
}

Result


Related Tutorials