EN
C# / .NET - string replace
1 points
In C# / .NET it is possible to replace part of string in few ways.
xxxxxxxxxx
1
string input = "My name is John.";
2
string output = input.Replace("John", "Kate");
3
4
Console.WriteLine(output);
Output:
xxxxxxxxxx
1
My name is Kate.
xxxxxxxxxx
1
Regex regex = new Regex("John");
2
3
string input = "My name is John.";
4
string output = regex.Replace(input, "Kate");
5
6
Console.WriteLine(output);
Output:
xxxxxxxxxx
1
My name is Kate.
xxxxxxxxxx
1
string pattern = "John";
2
3
string input = "My name is John.";
4
string output = Regex.Replace(input, pattern, "Kate");
5
6
Console.WriteLine(output);
Output:
xxxxxxxxxx
1
My name is Kate.