How do I replace the *first instance* of a string in .NET?

后端 未结 14 962
忘掉有多难
忘掉有多难 2020-11-22 16:41

I want to replace the first occurrence in a given string.

How can I accomplish this in .NET?

14条回答
  •  悲哀的现实
    2020-11-22 16:52

    using System.Text.RegularExpressions;
    
    RegEx MyRegEx = new RegEx("F");
    string result = MyRegex.Replace(InputString, "R", 1);
    

    will find first F in InputString and replace it with R.

提交回复
热议问题