且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何替换字符串中的花括号及其内容

更新时间:2022-12-28 12:42:49

使用 Regex.Replace:

string value = "6";
string sentence = "What is 3 x {contents}";
var result = Regex.Replace(sentence, "{.*?}", value); // What is 3 X 6

MSDN 是个好地方开始理解正则表达式

MSDN is a good place to start for understanding regex