Escape curly brackets around a template entry when using String.Format

Possible Duplicate:
String.Format exception when format string contains “{”

Does following possible using C# String.Format?

Required output "products/item/{itemId}"

I've tried escaping braces but this does not work:

const string itemIdPattern = "itemId";
string result = String.Format("products/item/{{0}}", itemIdPattern);

Preferably something more nice than

string result = String.Format("products/item/{0}{1}{2}", 
                              "{", 
                              itemIdPattern, 
                              "}");   

你需要每侧3个大括号 - 2个用于大括号,1个用于替换。

string result = String.Format("products/item/{{{0}}}", itemIdPattern);
链接地址: http://www.djcxy.com/p/51482.html

上一篇: string.format中的转义大括号会丢失。 可能的C#错误?

下一篇: 使用String.Format时,在模板条目周围使用大括号括起来