C# String Replace: Method & Examples

In C#, the method for replacing strings is by using the Replace method. This method allows you to search for a specified substring in a string and replace it with a new string. Here is an example:

string originalString = "Hello, World!";
string newString = originalString.Replace("Hello", "Hi");

Console.WriteLine(newString); // Output: Hi, World!

In the example above, we replaced the “Hello” in the original string with “Hi” using the Replace method, and then outputted the result to the console.

bannerAds