类的练习

//string 类

//string a = " abcdefg d ";
//int c = a.IndexOf("d");//从前面开始找,找到第一个,数他的位置
//int d=a.LastIndexOf("d");
//bool b = a.Contains("d");//是否包含此字符串
//Console.WriteLine(c);


//int b = a.Length;//长度
//Console.WriteLine(b);
//string c=a.Trim();//去掉前后空格
//Console.Write(c);
//Console.Write("\n");
//string d = a.TrimStart();//去掉前空格
//Console.Write(d);
//Console.Write("\n");
//string e = a.TrimEnd();//去掉后空格
//Console.Write(e);
//Console.Write("\n");
//string f = a.ToUpper(); //全部将小写字母转换为大写
//Console.Write(f);
//Console.Write("\n");
//string g = a.ToLower(); //全部将大写字母转换为小写
//Console.WriteLine(g);
//Console.Write("\n");
//string h = a.Substring(4);//索引号是从0开始的,里面一个值表示从这个索引开始一直截取到最后
//Console.Write(h);
////a=a .Substring(4);若不重新赋值 a没有变化
////两个值 表示从哪个索引号开始,截取多少长度
//Console.WriteLine(a.Substring(8));
//Console.WriteLine(a);
//string i = a.Substring(4,3);
//Console.WriteLine(i);


//a=a.Replace("de", "DE");
//Console.WriteLine(a);

//string j = "2012 12 23";
//string[] aa = j.Split(); //分割字符串,以什么字符
//foreach(string m in aa)
//{
// Console.WriteLine(m);
//}

//Console.ReadLine();


//math 类
//double a = 4.14;
//Console.WriteLine(Math.Ceiling(a));//取上线
//Console.WriteLine(Math .Floor(a));//取下线

//Console.WriteLine(Math.PI*a);//π 圆周率
//Console.WriteLine(Math .Sqrt(a));//开平方根

//Console.WriteLine(Math.Round(a));//四舍五入
//注意:基数.5的情况下,取上线
//偶数.5的情况下,取下线

//输入身份证号,截取生日,输出
//Console.Write("请输入你的身份证号:");
//string a = Console.ReadLine(); //370321199211163014
//if (a.Length == 18)
//{
// string y = a.Substring(6, 4);
// string b = a.Substring(10, 2);
// string c = a.Substring(12, 2);
// Console.WriteLine("你的出生年月日时"+y+"年"+b + "月" + c + "日");
// Console.ReadLine();
//}
//else
//{
// Console.WriteLine("输入错误");
//}


//练习 判断邮箱的格式是否正确
//1、有且只能有一个@
//2、不能以@开头
//3、@之后至少有一个.
//4、@和.不能靠一起
//不能以.结尾
//Console.Write("请输入你的邮箱账号");
//string a = Console.ReadLine();
//if (a.Contains("@")) //确定有没有@
//{
// int b = a.IndexOf("@");
// int c = a.LastIndexOf("@");
// if (b == c) //确定有且只有一个@
// {
// if (b != 0) //@不是第一位
// {
// string m = a.Substring(b);
// if (m.Contains(".")) //确定有没有“.”
// {
// int d = m.IndexOf("."); //确定“.”的位置
// if (d != 1) //确定“.”不和@一起
// {
// int e = m.LastIndexOf("."); //确定“.”是不是在最后一位
// if (e != m.Length - 1) //e!=m.length-1 e不是最后一位数

// {
// Console.WriteLine("邮箱格式正确!");
// }
// else
// {
// Console.WriteLine("输入有误");
// }
// }
// else
// {
// Console.WriteLine("输入XX");
// }
// }
// else
// {
// Console.WriteLine("输入有误");
// }
// }
// else
// {
// Console.WriteLine("你的输入有误");
// }
// }
// else
// {
// Console.WriteLine("输入有误");
// }
//}
//else
//{
// Console.WriteLine("你的输入有误;");
//}
//Console.ReadLine();


//随机数类 random
//Random ran =new Random();//初始化
//int a = ran.Next(10);//随机10以内的数
//Console.WriteLine(a);
//Console.ReadLine();


//随机出验证码,对照输入,判断是否正确
//for (; ; )
//{
// string a = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
// Random ran = new Random();
// string z = "";
// for (int i = 1; i <= 4; i++)
// {
// z += a.Substring(ran.Next(a.Length), 1);
// }
// Console.WriteLine("验证码是" + z);
// Console.WriteLine("请输入验证码");
// string shu = Console.ReadLine();
// if (shu.ToLower() == z.ToLower())
// {
// Console.WriteLine("输入正确");
// break;
// }
// else
// {
// Console.WriteLine("输入错误");
// }

// Console.Clear();

//}
// Console.ReadLine();

原文地址:https://www.cnblogs.com/banyue5026/p/5268230.html