replace the first three digits with the word "digit" - CSharp Language Basics

CSharp examples for Language Basics:Regex

Description

replace the first three digits with the word "digit"

Demo Code

using System;//from   w w  w  .  j  a  v a  2s.  co m
using System.Text.RegularExpressions;
class MainClass
{
   static void Main( string[] args )
   {
      string testString2 = "1, 2, 3, 4, 5, 6, 7, 8";
      Regex testRegex1 = new Regex( @"\d" );
      Console.WriteLine( "\nSecond test string: {0}", testString2 );
      // replace the first three digits with the word "digit"
      Console.WriteLine( "Replace first 3 digits by \"digit\": {0}", testRegex1.Replace( testString2, "digit", 3 ) );
   }
}

Result


Related Tutorials