Follow me on Twitter RSS FEED

Replace string with only first match in C#

Posted in
Code to replace string with only first match in C#
string ReplaceFirstOccurence(string wordToReplace, string replaceWith, string Input)
        {
            Regex r = new Regex(wordToReplace, RegexOptions.IgnoreCase);
            return r.Replace(Input, replaceWith, 1);
        }

0 comments:

Post a Comment