StringBuilder類相關操作

CSF践行發表於2024-08-18

            //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();

相關文章