// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; class MainClass { public static string ReplaceOne(string s, string fnd, string rpl) { int ix = s.IndexOf(fnd); if(ix >= 0) { return s.Substring(0, ix) + rpl + s.Substring(ix + fnd.Length); } else { return s; } } public static void Main(string[] args) { Console.WriteLine(ReplaceOne("abcabc", "b", "x")); } }