How to replace a substring in C Sharp/C# ?

By | July 12, 2011

Hi,

For replacing a substring in C Sharp/C#, use the following lines of code.

using System;

  class Class1
  {
    static void Main(string[] args)
    {
            string newStr = "Heaven";

            string finalStr = "CoderzWorld";

            finalStr = finalStr.Replace( "World", newStr);

            Console.WriteLine( finalStr);

    }
    }

Leave a Reply

Your email address will not be published. Required fields are marked *