Replace character/string in C#
To replace a character or string from a string we use Replace method. This method has two overloads.
First accepts a character which is to be replaced and new character to replace old character.
Second accepts string which is to be replaced and new string to replace old string.
stringFruit = "Orange";
Fruit = Fruit.Replace('e', 'E');
Fruit = Fruit.Replace("an", "AN");
Console.WriteLine(Fruit);
Output
OrANgE
Comments
Post a Comment