标签:
//string a = "aldsfdh";
////bool q = a.Contains("dd");//是否包含此字符串
//int o = a.IndexOf("h");
//Console.WriteLine(o);
////int p = a.LastIndexOf("d");
////Console.WriteLine(p);
//int b = a.Length;//长度
//Console.WriteLine(b);
//string c = a.Trim();//去掉前后空格
//Console.Write(c);
//string d = a.TrimStart();//去掉前空格
//Console.Write(d);
//string e = a.TrimEnd();//去掉后空格
//Console.Write(e);
//string f = a.ToUpper();//全部将小写字母转换为大写
//Console.Write(f);
//string g = a.ToLower();//全部将大写字母转换为小写
//Console.Write(g);
////索引是从0开始的
//string h = a.Substring(4);//里面一个值,表示从这个索引值开始一直截取到最后
//Console.WriteLine(h);
//Console.WriteLine(a.Substring(8));//a=a.Substring(8);//若不重新赋值,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( );//分割字符串,
//Console.Write("请输入邮箱:");
//for (; ; )
//{
// string t = Console.ReadLine();
// bool q = t.Contains("@");//先判断有没有@
// if (q)
// {
// int a = t.IndexOf("@");
// int b = t.LastIndexOf("@");
// for (; ; )
// {
// if (a == b)//通过索引从前面数@,和从后面数@,索引值是不是一样
// {
// for (; ; )
// {
// if (a != 0)//判断@是不是开头 ,@的索引值不是0
// {
// for (; ; )
// {
// int c = t.IndexOf(".");
// if (c > a)//先判断有没有".",这一步忘了
// {
// for (; ; )
// {
// if (c > (a + 1))//判断@和“.”是不是挨着
// {
// int d = t.LastIndexOf(".");
// int e = t.Length;
// if (d != (e - 1))//判断是不是以“.”,结尾
// {
// Console.WriteLine("格式正确。");
// break;
// }
// else
// {
// Console.WriteLine("格式不对,重输:");
// }
// break;
// }
// else
// {
// Console.WriteLine("格式不对,重输:");
// }
// break;
// }
// }
// else
// {
// Console.WriteLine("格式不对,重输:");
// }
// break;
// }
// }
// else
// {
// Console.WriteLine("格式不对,重输:");
// }
// break;
// }
// }
// else
// {
// Console.WriteLine("格式不对,重输:");
// }
// }
// }
// else
// {
// Console.WriteLine("格式不对,重输:");
// }
//}
//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));//四舍五入
////ps.奇数.5的情况下,取上线。 偶数.5的情况,取下线
//输入身份证号,截取生日,输出
//37030319901204 0027 6--14
//Console.Write("输入身份证号:");
//for (; ; )
//{
// string a = Console.ReadLine();
// int b = a.Length;
// if (b == 18)
// {
// string i = a.Substring(6, 8);
// Console.WriteLine(i);
// break;
// }
// else
// {
// Console.Write("重新输入身份证号:");
// }
//}
//Console.ReadLine();
//随机数类
//int a = ran.Next(10);
//Console.WriteLine(a);
//随机出验证码,对照输入,判断是否正确
string s = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
Random ran = new Random();
//自己做的
//int a = ran.Next(s.Length);
//int b = ran.Next(s.Length);
//int c = ran.Next(s.Length);
//int d = ran.Next(s.Length);
//Console.WriteLine(s.Substring(a, 1) + s.Substring(b, 1) + s.Substring(c, 1) + s.Substring(d, 1));
//string m = (s.Substring(a, 1) + s.Substring(b, 1) + s.Substring(c, 1) + s.Substring(d, 1)).ToLower();//开始用readline()接收,错了。
//Console.Write("请输入验证码:");
//string n = (Console.ReadLine()).ToLower();
//if (m==n)
//{
// Console.Write("输入正确。");
//}
//else
//{
// Console.Write("输入有误。");
//}
//Console.ReadLine();
//Console.Clear();//清屏
//Console.WriteLine("chongshu");
//套用老师的方法
for (; ; )
{
string q = "";
for (int i = 1; i <= 4; i++)
{
q += s.Substring(ran.Next(s.Length), 1);
}
Console.WriteLine(q);//q是string型,是字符串。+遇到string型变连接符,不会相加
Console.WriteLine("请输入验证码:");
string w = Console.ReadLine();
if (q.ToLower() == w.ToLower())//都变小写,或者都变大写
{
Console.Write("输入正确。");
break;
}
else
{
Console.Clear();//清屏
Console.WriteLine("输入有误");
}
}
Console.ReadLine();
标签:
原文地址:http://www.cnblogs.com/xingfudehuanyan/p/5277024.html