Posts tagged “string”

C# Replace method

The .Replace function is a string method used to replace characters or strings in a string with another character/string else. In its easiest form you would type something like: string.Replace(“replacethistext”,”withthistext”). Replace(string,string) String text = “My favourite colour is red.”; string correctedText = text.Replace(“red”, “green”); Console.WriteLine(text); Console.WriteLine(correctedText); Console.ReadKey(); Will result in: My favourite colour is red. [...]