首页 > 解决方案 > 如何替换括号中的字段

问题描述

string MemberId = "1001";
string Password = "123";
string AttendDate = "01/01/2020";

string template = 
  "Dear Member your id is {{id}} and password is {{pwd}} kindly attend on {{date}}";

输出应该是:

string template = 
  "Dear Member your id is 1001 and password is 123 kindly attend on 01/01/2020";

标签: c#.net

解决方案


您可以使用字符串插值

string template = $"Dear Member your id is {MemberId} and password is {Password} kindly attend on {AttendDate}";

假设它template被声明为字符串文字。


推荐阅读