不必刻意记忆,实际写代码过程中,编辑器会有提示
static void Main(string[] args)
{
StringBuilder s1 = new StringBuilder();
StringBuilder s2 = new StringBuilder(20);
StringBuilder s3 = new StringBuilder("Hello World!");
StringBuilder s4 = new StringBuilder(20,50);
StringBuilder s5 = new StringBuilder("Hello World!",50);
StringBuilder s6 = new StringBuilder("Hello World!",2,6,50);
Console.WriteLine(s6);
bool xBool = true;
bool yBool = false;
char star = '*';
string s = "interesting";
string ss = "ab";
char[] ch = { 'a', 'b', 'c' };
int iNum = 789;float fNum = 2.34f;
Console.WriteLine(s3.Append(yBool));
Console.WriteLine(s3.Append(star,3));
Console.WriteLine(s3.Append(s,2,5));
Console.WriteLine(s3.AppendFormat("先加{0},注意有逗号,再加{1}",iNum,fNum));
Console.WriteLine(s6.Insert(2,yBool));
Console.WriteLine(s6.Insert(2,ss,2)); //ss只能是字符串
Console.WriteLine(s6.Insert(1,ch,1,2)); //ch只能是字符数组
Console.WriteLine(s6.Remove(5,4));
Console.WriteLine(s6.Replace('a','A'));
Console.WriteLine(s6.Replace("bcl","hahaha"));
Console.WriteLine(s6.Replace('A','a',5,3));
Console.WriteLine(s6[4]);
Console.WriteLine(s6.Length);
}
字符串的Split方法
两种常用的格式:
字符串.Split(字符数组);
字符串.Split(字符数组,返回的字符串的最大的数量);
string[] strArray = sb1.ToString().Split(new Char[] { ',', '.', '!', ':', ';' });
string[] strArray = sb1.ToString().Split(new Char[] { ',', '.', '!', ':', ';' },3);