Replace multiple words in string

后端 未结 8 1112
独厮守ぢ
独厮守ぢ 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:37

    Use String.Format:

    const string message = "Dear {0}, Please call {1} to get your {2} from {3}";
    string name = "Bob";
    string callName = "Alice";
    string thingy = "Book";
    string thingyKeeper = "Library";
    string customMessage = string.Format(message, name, callName, thingy, thingyKeeper);
    

提交回复
热议问题