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