C# Replace Function: Usage Guide

In C#, you can use the Replace method to replace a specified substring within a string. The usage of the Replace method is as follows:

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

Console.WriteLine(newString); // 输出:Hello, Universe!

In the example above, we used the Replace method to replace “World” with “Universe” in the original string, and assigned the new replaced string to the variable newString. Finally, we printed out the new string using the Console.WriteLine method.

bannerAds