Replace multiple words in string

后端 未结 8 1141
独厮守ぢ
独厮守ぢ 2020-12-18 19:02

I have multiple words I want to replace with values, whats the best way to do this?

Example: This is what I have done but it feels and looks so wrong



        
8条回答
  •  难免孤独
    2020-12-18 19:33

    Try this code:

    string MyString ="This is the First Post to Stack overflow";
    MyString = MyString.Replace("the", "My").Replace("to", "to the");
    

    Result: MyString ="This is My First Post to the Stack overflow";

提交回复
热议问题