Replace multiple words in string

后端 未结 8 1083
独厮守ぢ
独厮守ぢ 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);
    
    0 讨论(0)
  • You could use String.Format.

    string.Format("Dear {0}, your booking is confirmed for the {1}", 
       client.FullName, event.EventDate.ToString());
    
    0 讨论(0)
提交回复
热议问题