1 //StringBuilder表示值为可变字符序列的对象 2 3 //StringBuilder的创建 4 StringBuilder sb = new StringBuilder("hello world"); 5 6 //StringBuilder类的常用方法 7 /*1.Append 将文本或字符串追加到指定的对象末尾 8 *2.AppendFormat 自定义变量的格式并将这些值追加到指定对象的末尾 9 *3.Insert 将字符串添加到StringBuilder对象中的指定位置 10 *4.Remove 从当前StringBuilder中移除指定数量的字符 11 *5.Replace 用另外一个字符串来替换StringBuilder中的字符 12 */ 13 14 //在sb后追加字符串 15 sb.Append("!"); 16 Console.WriteLine(sb); 17 sb.AppendFormat("{0:C}", 1000); 18 Console.WriteLine(sb); 19 20 sb.Insert(6, "one "); 21 Console.WriteLine(sb); 22 23 sb.Remove(6, 4); 24 Console.WriteLine(sb); 25 26 sb.Replace("hello", "Hello"); 27 Console.WriteLine(sb);