Replace String in C#

In this article we will discuss about how to replace string in C#.
  • 2891

The Replace method replaces all occurrences of a specified character in a string. For example, the following source code replaces all occurrences of string "author" with string "writer" in the string.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication4
    class Program
        static void Main(string[] args)
            string sentence = "Mahesh Chand is an author and founder of C# Corner";
            Console.WriteLine("Original String: {0}", sentence);
            sentence = sentence.Replace("author", "writer");
            Console.WriteLine("Final String");

Further Readings
You may also want to read these related articles.

Ask Your Question 

Got a programming related question? You may want to post your question here


More Articles

© 2020 DotNetHeaven. All rights reserved.