Posted By

spark9 on 01/07/10


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

derekholmes


Replace First


 / Published in: C#
 

  1. string ReplaceFirst(string text, string search, string replace)
  2. {
  3. int pos = text.IndexOf(search);
  4. if (pos < 0)
  5. {
  6. return text;
  7. }
  8. return text.Substring(0, pos) + replace + text.Substring(pos + search.Length);
  9. }

Report this snippet  

You need to login to post a comment.