StringBuilder类相关操作

 

            //StringBuilder的定义及相关操作
            int int1 = 100;
            StringBuilder str1 = new StringBuilder("哈哈哈,", 100);

            str1.Append("你变了"); //Append函数
            Console.WriteLine(str1);

            str1.AppendFormat("{0:C}", int1);//AppendFormat函数;  格式化为钱币格式;
            Console.WriteLine(str1);

            str1.Insert(4, "你个死鬼,");//Insert函数
            Console.WriteLine(str1);

            str1.Remove(str1.Length - 7, 7);//Remove函数
            Console.WriteLine(str1);

            str1.Replace("你个死鬼,", "你个老鬼,");//Replace函数
            Console.WriteLine(str1);

            Console.ReadLine();

 

posted @ 2024-08-18 18:19  CSF践行  阅读(3)  评论(0编辑  收藏  举报