How to use .Replace() in c# code example

Example 1: c sharp string replace

// You can use the function 'Replace()' to replace all instances
// of a string or character with a given string or character.
str  = "Hello World!"
str.Replace('o', 'e');
// Output: "Helle Werld!"

Example 2: String.Replace() c#

String s = "aaa";
Console.WriteLine($"The initial string: {s}");
s = s.Replace("a", "b").Replace("b", "c").Replace("c", "d");
Console.WriteLine($"Final String: {s}");

// Returns "Final String: ddd"