replace the word "stars" with "carets" and display the result - CSharp Language Basics

CSharp examples for Language Basics:Regex

Description

replace the word "stars" with "carets" and display the result

Demo Code


using System;/*from w ww.  j a va  2s . c  om*/
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 the word "stars" with "carets" and display the result
      testString1 = Regex.Replace( testString1, "stars", "carets" );
      Console.WriteLine( "\"carets\" substituted for \"stars\": {0}", testString1 );
   }
}

Result


Related Tutorials