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

后端 未结 14 1118
忘掉有多难
忘掉有多难 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 17:02

    For anyone that doesn't mind a reference to Microsoft.VisualBasic, there is the Replace Method:

    string result = Microsoft.VisualBasic.Strings.Replace("111", "1", "0", 2, 1); // "101"
    

提交回复
热议问题