C# replace
String.replace() method replaces a specific substring with a new substring, or a specific char with a new char.
1
2
3
4
5
string str="John is 50 years old";
string str2 = str.Replace('s', 't');
string str="John is 50 years old";
string str2 = str.Replace("is", "should be");
Regex.Replace() method replace a substring with specific pattern.
1
2
3
using System.Text.RegularExpressions;
string str = "csharp regular expression";
str = Regex.Replace(str, @"regular ", "");