This should do the trick. oldValue is the value you want to find and replace, newValue is the value you want to replace with.
static void Main(string[] args)
{
string transport = "car motorcycle motorcycle plane train";
transport = ReplaceFirst(transport, "motorcycle", "not motorcycle");
Console.WriteLine(transport);
// prints "car not motorcycle motorcylce plane train
}
static string ReplaceFirst(string values, string oldValue, string newValue)
{
int index = values.IndexOf(oldValue);
if (index == -1) return values;
values = values.Substring(0, index)
+ newValue
+ values.Substring(index + oldValue.Length);
return values;
}
I'm reading this question to mean that you don't want to use LINQ.*