zoukankan      html  css  js  c++  java
  • string类 截取的长度 是否包含某个数

     //输入身份证号,截取生日,输出
                //370303199003053330
                //Console.Write("请输入身份证号:");
                //string id = Console.ReadLine();
                //if (id.Length == 18)
                //{
                //    string year = id.Substring(6,4);
                //    string month = id.Substring(10,2);
                //    string day = id.Substring(12,2);
                //    Console.WriteLine("您的生日是:"+year+"年"+month+"月"+day+"日");
                //}
                //else
                //{
                //    Console.WriteLine("输入有误!");
                //}
    
    
                //Console.ReadLine();
    
    
    
                //邮箱格式
                //1.有且只有一个@         
                //2.不能以@开头
                //3.@和.不能在一起
                //4.@后至少有一个.
                //5.不能以.结尾
                //Console.Write("请输入你的邮箱账号:");
                //string mail = Console.ReadLine();
                //bool a = mail.Contains("@");
                //if (a == true)
                //{
                //    int b = mail.IndexOf("@");
                //    int c = mail.LastIndexOf("@");
                //    if (b == c)
                //    {
                //        if (b != 0)
                //        {
                //            string mail1 = mail.Substring(b);
                //            if (mail1.Contains("."))
                //            {
                //                int d = mail1.IndexOf(".");
                //                if (d != 1)
                //                {
                //                    int e = mail1.LastIndexOf(".");
                //                    if (e != mail1.Length - 1)
                //                    {
                //                        Console.WriteLine("邮箱格式输入正确!");
                //                    }
                //                    else
                //                    {
                //                        Console.WriteLine("输入有误!");
                //                    }
                //                }
                //                else
                //                {
                //                    Console.WriteLine("输入有误!");
                //                }
                //            }
                //            else
                //            {
                //                Console.WriteLine("输入有误!");
                //            }
                //        }
                //        else
                //        {
                //            Console.WriteLine("输入有误!");
                //        }
                //    }
                //    else
                //    {
                //        Console.WriteLine("输入有误!");
                //    }
                //}
                //else
                //{
                //    Console.WriteLine("输入有误!");
                //}
    
    
                //string s = "abcdefghijklmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789";
    
                //随机数类  Random
                //Random ran = new Random();//初始化
                //double a = ran.Next(10);
                //int b = ran.Next(s.Length);
                //Console.WriteLine(a);
    
                //Console.ReadLine();
    
    
                //随机出验证码,对照输入,判断是否正确
                //string s = "abcdefghijklmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789";
                //Random ran = new Random();
                //string biao = "";
                //for (int i = 1; i <= 4; i++)
                //{
                //    biao += s.Substring(ran.Next(s.Length),1);
                //}
                //Console.WriteLine(biao);
                //Console.Write("请输入验证码:");
                //string shu = Console.ReadLine();
                //if (shu.ToLower() == biao.ToLower())
                //{
                //    Console.WriteLine("输入正确!");
                //}
                //else
                //{
                //    Console.WriteLine("输入错误!");
                //}
                //Console.ReadLine();
                //Console.Clear();
                //Console.WriteLine("123");
                //Console.ReadLine();
    
    
                string s = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
                Random ran = new Random();
                for (; ; )
                {
                    string a = "";
                    for (int i = 1; i <= 4; i++)
                    {
                        a += s.Substring(ran.Next(s.Length), 1);
                    }
                    Console.WriteLine(a);
    
                    Console.WriteLine("请输入验证码:");
                    string b = Console.ReadLine();
                    if (b.ToLower() == a.ToLower())
                    {
                        Console.WriteLine("输入正确");
                        break;
                    }
                    else
                    {
                        Console.Clear();
                        Console.WriteLine("输入错误");
                    }
                }
                Console.ReadLine();
    
  • 相关阅读:
    Windows 之 CMD命令
    关于生sql中的空值
    电商物流仓储WMS业务流程
    VS 在代码中括号总是跟着类型后面
    DataTable的Select()方法
    sqlserver 系统表芝士
    CodeMix入门基础知识
    DevExpress v18.1新版亮点——CodeRush for VS篇(二)
    DevExpress v18.1新版亮点——CodeRush for VS篇(一)
    DevExpress v18.1新版亮点——Data Access篇
  • 原文地址:https://www.cnblogs.com/xingfudehuanyan/p/5269276.html
Copyright © 2011-2022 走看看