1.StringBuilder类
1.1程序代码
static void Main(string[] args)
{
StringBuilder bf1 = new StringBuilder();
StringBuilder bf2 = new StringBuilder(10);
StringBuilder bf3 = new StringBuilder("Hello Kitty!");
StringBuilder bf4 = new StringBuilder("1234567890");
Console.WriteLine("{0} {1} {2} {3}", bf1.Length, bf2.Length, bf3.Length, bf4.Length);
Console.WriteLine("{0} {1} {2} {3}", bf1.Capacity,bf2.Capacity, bf3.Capacity,bf4.Capacity);
StringBuilder bf5 = new StringBuilder("Hello Kitty!");
bf5.EnsureCapacity(28);
Console.WriteLine(bf5.Length);
Console.WriteLine(bf5.Capacity);
bf5.Length = 5;
bf5.Capacity = 9;
Console.WriteLine(bf5);
StringBuilder bf6 = new StringBuilder("Hello Kitty!");
bf6.Length = 20;
Console.WriteLine(bf6 + "尾");
StringBuilder bf7 = new StringBuilder("Kitty is ");
int intValue = 3;
bf7.Append(intValue);
string stringValue = " years old";
bf7.Append(stringValue);
char charValue = ',';
bf7.Append(charValue);
char[] charArray = { ' ', 's', 'h', 'e',' ','i', 's',' ' };
bf7.Append(charArray);
double doubleValue = 2.5;
bf7.Append(doubleValue);
bf7.Append("Kg. That is ");
bool boolValue = true;
bf7.Append(boolValue);
bf7.Append('!');
Console.WriteLine(bf7);
StringBuilder bf8 = new StringBuilder(new string('a', 15));
Console.WriteLine("Length={0}\tCapacity={1}",bf8.Length,bf8.Capacity);
bf8.Append(new string('a', 1));
Console.WriteLine("Length={0}\tCapacity={1}", bf8.Length, bf8.Capacity);
bf8.Append(new string('a', 1));
Console.WriteLine("Length={0}\tCapacity={1}", bf8.Length, bf8.Capacity);
bf8.Append(new string('a', 14));
Console.WriteLine("Length={0}\tCapacity={1}", bf8.Length, bf8.Capacity);
bf8.Append(new string('a', 1));
Console.WriteLine("Length={0}\tCapacity={1}", bf8.Length, bf8.Capacity);
bf8.Append(new string('a', 1));
Console.WriteLine("Length={0}\tCapacity={1}", bf8.Length, bf8.Capacity);
bf8.Append(new string('a', 30));
Console.WriteLine("Length={0}\tCapacity={1}", bf8.Length, bf8.Capacity);
bf8.Append(new string('a', 1));
Console.WriteLine("Length={0}\tCapacity={1}", bf8.Length, bf8.Capacity);
bf8.Append(new string('a', 1));
Console.WriteLine("Length={0}\tCapacity={1}", bf8.Length, bf8.Capacity);
bf8.Append(new string('a', 62));
Console.WriteLine("Length={0}\tCapacity={1}", bf8.Length, bf8.Capacity);
bf8.Append(new string('a', 1));
Console.WriteLine("Length={0}\tCapacity={1}", bf8.Length, bf8.Capacity);
bf8.Append(new string('a', 132));
Console.WriteLine("Length={0}\tCapacity={1}", bf8.Length, bf8.Capacity);
Console.WriteLine(bf8);
StringBuilder bf9 = new StringBuilder();
decimal i = 19.23m;
decimal j = 73.7m;
bf9.AppendFormat("{0,8:c2}\n+{1,7:c2}\n---------\n{2,8:c2}",i,j,i+j);
Console.WriteLine(bf9);
StringBuilder bf10 = new StringBuilder("Kitty year old,she is Kg,that is !");
string stringValue1 = "is";
bf10.Insert(6,stringValue1);
int intValue1 = 3;
bf10.Insert(9,intValue1);
char charValue1 = 's';
bf10.Insert(15,charValue1);
double doubleValue1 = 2.5;
bf10.Insert(28,doubleValue1);
bool boolValue1 = true;
bf10.Insert(42,boolValue1);
Console.WriteLine(bf10);
StringBuilder bf11 = new StringBuilder("Happy birthday Jack");
bf11.Replace("Jack", "Kitty");
Console.WriteLine(bf11);
StringBuilder bf12 = new StringBuilder("Harvard is a famous university!");
bf12.Remove(13, 7);
Console.WriteLine(bf12);
}
2.char类
2.1程序代码
private void button1_Click(object sender, EventArgs e)
{
char character=Convert.ToChar(textBox1.Text);
string output = "";
output += "为数字:" + char.IsDigit(character) + "\r\n";
output += "为字母:" + char.IsLetter(character) + "\r\n";
output += "为小写:" + char.IsLower(character) + "\r\n";
output += "为大写:" + char.IsUpper(character) + "\r\n";
output += "为标点:" + char.IsPunctuation(character) + "\r\n";
output += "转大写:" + char.ToUpper(character) + "\r\n";
output += "转小写:" + char.ToLower(character) + "\r\n";
textBox2.Text=output;
}