In this article we will explain how to use Replace method or what is Replace method in c# with example.


In c# programming language string Replace() method is a string method, the Replace()  method is used to replace all the specified Unicode characters or specified string from the current string object and returns a new modified string.

C# String Replace Method Example

Following is the example of using Replace() method to replace a particular part of string or a character in c# programming language.

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SQLTutorialsPoint
    class Program
        static void Main(string[] args)
            string msg = "Hi Guest hello";
            string nmsg = msg.Replace("hello", "Welcome");
            Console.WriteLine("Old:{0}", msg);
            Console.WriteLine("New:{0}", nmsg);
            string y = "1 2 3 4 5 6 7 8 9 10";
            string x = y.Replace(" ", ",");
            Console.WriteLine("Old:{0}", y);
            Console.WriteLine("New:{0}", x);
            Console.WriteLine("\nPressEnter Key to Exit..");

As you see above example, we used a Replace() method to replace particular part of string or a character in given string and returning a new string.


When we execute above c# program, we will get the result like as shown below.

 How to Use String Replace Method in C# with Example

In this article we have learned. How we can use Replace() method to replace a particular part of  string or a character in c# programming language.  

I hope it will help to you after reading.


Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

You may also like