c# - 如何替换括号中的字段
问题描述
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";
解决方案
您可以使用字符串插值:
string template = $"Dear Member your id is {MemberId} and password is {Password} kindly attend on {AttendDate}";
假设它template
被声明为字符串文字。
推荐阅读
- laravel - 如何更改自定义 FormRequest 的 http 响应状态?
- ffmpeg - FFmpeg drawtext 和使用 sendcmd/zmq 的实时坐标
- html - 引导程序 4:添加行或添加 col-12 之间的区别?
- c# - 从快速操作和重构中提取缺少的接口
- java - Android 片段中的 Mapbox SDK
- rest - REST 响应为 {}
- php - 如何检查您是否在分页单篇文章的最后一页?
- html - 如何动态分隔表格(以 div 开始,以其他 div 结束)
- c# - 使用 Powershell (New-ScriptBlockCallback) 的 Httplistener 异步处理 - 仍然阻塞
- regex - 正则表达式匹配所有内容,直到第一次出现 Golang 风格的字符串