您的位置:首页 > 其它

System.FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list

2015-03-04 17:18 1156 查看
static void Main(string[] args)
{
StringBuilder sb = new StringBuilder();
string test = "124454664{0}89jnhb";
string formattedMessage = string.Format(test, args);

}


主要原因是字符串中有{}, 被string.Format调用时报错。

Replace即可。

StringBuilder sb = new StringBuilder();
string test = "124454664{0}89jnhb";
test = test.Replace("{", "[").Replace("}", "]");
string formattedMessage = string.Format(test, args);


或者 将 { 替换为 {{
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐