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

CSharp examples for Language Basics:Regex

Description

replace every word with "word" and display the result

Demo Code

using System;// w w  w.  j  av  a2 s  . co  m
using System.Text.RegularExpressions;
class MainClass
{
    static void Main(string[] args)
    {
        string testString = "1, 2, 3, 4, 5, 6, 7, 8";
        // replace every word with "word" and display the result
        Console.WriteLine("Every word replaced by \"word\": {0}", Regex.Replace(testString, @"\w+", "word"));
    }
}

Result


Related Tutorials