This code snippet is used to replace the string without using the replace function using C#.Most of the times we get a requirement to replace the String with a certain string.
class StringReplaceWithOutUsingFunction
{
public static void Main(string[] args)
{
string sentence = "Welcome to English Club Grammar for English learners.";
string[] parts = sentence.Split(' ');
string matchString = "English";
string replaceString = "engLISh";
for (int i = 0; i < parts.Count(); i++)
{
parts[i] = parts[i].Length == 7 == true && parts[i] == matchString == true ? parts[i] = replaceString : parts[i];
}
foreach (string item in parts)
{
Console.Write(item + " ");
}
Console.ReadKey();
}
}