C# replace

String.replace() method replaces a specific substring with a new substring, or a specific char with a new char.

string str="John is 50 years old";
string str2 = str.Replace('s', 't'); //str2=John it 50 yeart old
//---------------------------------
string str="John is 50 years old";
string str2 = str.Replace("is", "should be"); //John should be 50 years old

Regex.Replace() method replace a substring with specific pattern.
using System.Text.RegularExpressions;
string str = "csharp regular expression";
str = Regex.Replace(str, @"regular ", ""); //csharp expression



endmemo.com © 2017  Terms of Use | Home