//string Str1 = "友情相逢";
//string Str2 = "用一生爱你";
//#region char的使用
//char a = 'a';
//Console.WriteLine("IsLetter方法判断a是否为字母:{0}", Char.IsLetter(a));
//Console.WriteLine("IsDigit方法判断a是否为数字:{0}", Char.IsDigit(a));
//Console.WriteLine("IsLower方法判断a是否为小写字母:{0}", Char.IsLower(a));
//Console.WriteLine("IsUpper方法判断a是否为大写字母:{0}", Char.IsUpper(a));
//Console.WriteLine("IsWhiteSpace方法判断a是否为空白:{0}", Char.IsWhiteSpace(a));
//#endregion
//#region String类的使用
//string Str1 = "用一生爱护你!";
//char Str2 = Str1[1];
//char Str3 = Str1[2];
//Console.WriteLine("字符串Str1中第二个字符是:{0}", Str2);
//Console.WriteLine("字符串Str1中第三个字符是:{0}", Str3);
//#endregion
//#region Conpare/CompareTo比较字符串的使用
//Console.WriteLine(string.Compare(Str1, Str2));
//Console.WriteLine(string.Compare(Str1, Str1));
//Console.WriteLine(string.Compare(Str2, Str1));
//Console.WriteLine(Str1.CompareTo(Str2));
//Console.WriteLine(string.Equals(Str1,Str2)); //判断两个字符串是否相等
//#endregion
//#region ForMat格式化输出字符串
//string newstr = String.Format("{0},{1}!!!", Str1, Str2); //ForMat格式化字符串
//Console.WriteLine(newstr);
//DateTime dt = DateTime.Now;
//string time1 = string.Format("{0:D}", dt);
//string time2 = string.Format("{0:T}", dt);
//string time3 = string.Format("{0:G}", dt);
//Console.Write(time1);
//Console.WriteLine(time2);
//Console.WriteLine(time3);
//#endregion
//#region 截取字符串
//string Str3 = "";
//Str3 = Str1.Substring(1, 3);
//Console.WriteLine(Str3);
//#endregion
//#region 分割字符串
//string Str3 = "用!一生,下载";
//char[] separator = { '!', ',' };
//String[] splitstrings = new String[20];
//splitstrings = Str3.Split(separator);
//for (int i = 0; i <= splitstrings.Length; i++)
//{
// Console.WriteLine("item{0}:{1}", i, splitstrings[i]);
//}
//#endregion
//#region 插入和填充字符串
//string str3 = "下载";
//string str4;
//str4 = str3.Insert(0, "用一生");
//string str5 = str4.Insert(5, "你");
//Console.WriteLine(str5);
//string str6 = "*+_+*";
//string str7 = str6.PadLeft(6, '('); //在字符串左侧添加,确保添加后的总字符串为6
//string str8 = str7.PadRight(7, ')');
//Console.WriteLine("补充字符串之前" + str6);
//Console.WriteLine("补充字符串之后" + str8);
//#endregion
//#region 删除字符串
//string str3 = "用一生下载你";
//string str4 = str3.Remove(3); //3为所以字符 往后的都删掉
//Console.WriteLine(str4);
//string str5 = str3.Remove(0, 3); //0为索引,3为删除的字符数
//Console.WriteLine(str5);
//#endregion
//#region 字符串的复制
//string str = "我爱你forever";
//string Str;
//Str = String.Copy(str); //将str复制给Str
//Console.WriteLine(Str);
//string str3 = "用一生下载你";
//char[] str4 = new char[100];
//str3.CopyTo(1, str4, 0, 4); //第一个参数是原字符要复制的起始位置,第二个是新字符,第三个是新字符的复制的起始位置,第四个是复制的字符个数
//Console.WriteLine(str4);
//#endregion
//string a = "one world ,one dream";
//string b = a.Replace(',','*'); // 字符的替换用单引号
//Console.WriteLine(b);
//string c = a.Replace("one world","One World"); //字符串替换用双引号
//Console.WriteLine(c);
|
请发表评论