public static string ReplaceString(string whom, string what, string with) { int j = -1; int i = whom.IndexOf(what); if (i == -1) return whom; StringBuffer b = new StringBuffer(); b.ensureCapacity(whom.Length); while (i > -1) { b.append( whom.Substring(j + what.Length, i - j - what.Length) + with ); j = i; i = whom.IndexOf(what, i + what.Length); } b.append( whom.Substring(j + what.Length) ); return b.ToString(); }