如何动态使用字符串生成器AppendFormat
。我的代码如下显示一个错误。在MVC c#中如何做到这一点?如何在c#中动态添加字符串AppendFormat
代码:
var s = new StringBuilder();
s.AppendFormat("\"{0}\",\"{1}",
"test1",
"test2"
);
for(var i = 2; i < 10 ; i++)
{
s.AppendFormat(",\"{"+i+"}\"", "loop"); // error shows here
}
您正试图建立一个格式字符串与字符串格式化?这听起来错了吗?如果你已经有了这些数据,直接建立字符串。 – Jodrell
如果你真的要做到这一点,你不应该看这个问题和答案http://stackoverflow.com/questions/91362/how-to-escape-brackets-curly-braces-in-a-format -string式网。 – Jodrell