* StringBuild 初始容量是 32
* 1、属性:
* Length:现有内容长度;
* Capacity:StringBuild当前最大容量
*
* 2、
* 通过 设置Length=10,可以自动裁剪字符串,若原本不足10个时,用空格代替
//1、默认容量(默认 最大容量=32) StringBuilder buffer = new StringBuilder(); Console.WriteLine(string.Format("StringBuild的Length={0},Capacity={1}",buffer.Length,buffer.Capacity)); //2、自动分配最大容量(2倍原则) buffer.Append("Hello,how are you?Hello,how are you?"); Console.WriteLine(string.Format("StringBuild的Length={0},Capacity={1}", buffer.Length, buffer.Capacity)); //3、手动分配 最大容量; buffer.Capacity = 100; Console.WriteLine(string.Format("StringBuild的Length={0},Capacity={1}", buffer.Length, buffer.Capacity)); //4、通过Length截取字符串 buffer.Length = 10; Console.WriteLine(string.Format("StringBuild的Length={0},Capacity={1}", buffer.Length, buffer.Capacity));