湖边的白杨树

探索是一种乐趣

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
        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);
   

或者 将 { 替换为 {{

posted on 2015-03-04 17:18  fdyang  阅读(5548)  评论(0编辑  收藏  举报