首页 > 代码库 > date time 和string

date time 和string

Break 彻底终断循环

Continue 中断本次循环,进入下次循环

 

 

 

 

            //s后边的点代表“的”的意思,点后边出现的一系列应用中扳手代表名词,即属性。箱子代表动词,即方法。

            string s = "   holle    ";

            Console.WriteLine(s.Length );//名词   s字符窜长度 即多少个字符 不是字节数

           // 例:本题结果显示2

            string m = "您好";

            Console.WriteLine(m.Length);

            */

 

 

            //以下全是动词  动词后面必须有括号   数字符串长度从一开始数,数位置从零开始数

            //看括号内是不是能输入东西  将光标放在括号中间  摁ctrl+shift+空格 

            string s = "   Holle   Baby    ";

            Console.WriteLine(s.Trim()+"吃饭");        //压缩两边的空格  内容间的空格不能删

            Console.WriteLine(s.TrimStart() + "吃饭");//压缩开头的空格 

            Console.WriteLine(s.TrimEnd() + "吃饭");   //压缩末尾的空格

 

 

            Console.WriteLine(s.ToUpper());   //全部变成大写

            Console.WriteLine(s.ToLower ());   //全部变成小写

 

 

            Console.WriteLine(s.IndexOf ("o") );   //开始出现该符号在第几位

            Console.WriteLine(s.LastIndexOf ("o"));  // 最后出现该符号在第几位

            Console.WriteLine(s.Substring (5,3));   //从第几位开始截 , 截几个字符

            Console.WriteLine(s.Substring(5));    // 从第几位开始截  一直到结束

           

 

 

            Console.WriteLine(s.StartsWith ("o"));   //判断 开头是不是本字符(这三个都是布尔型)

            Console.WriteLine(s.EndsWith ("o"));     //判断 结尾是不是本字符

            Console.WriteLine(s.Contains("o"));     //判断  字符串中是否包括本字符

 

 

            Console.WriteLine(s.Replace ("o","9"));   //将本字符串中的o替换成9后的字符

 

 

 

            string a = @"c:\able\mmmm\ss.txt";//在将某个文件赋值时,会产生转义字符!以前用\\取消转义,现在只需加@即可

 

 

 

 

 

            /*

            DateTime n = new DateTime();      //创建新时间 括号内可手输

            Console.WriteLine(n);            //0001/1/1 星期一 上午12:00:00

            */

 

            /*

            DateTime n = new DateTime(2001,03,02,12,02,21);//创建新时间 手输

            Console.WriteLine(n);                        // 2001/3/2 星期五 下午12:02:21

            */

            /*

            DateTime n = new DateTime(2001, 3, 2, 12, 2, 21);//创建新时间 手输

            Console.WriteLine(n);                       // 2001/3/2 星期五 下午12:02:21

            */

 

 

 

 

            /*

            DateTime m = DateTime.Now;

            

             Console.WriteLine(m.ToString ("yyyy年MM月dd日hh时mm分ss秒"));//  2014年08月20日04时05分32秒  ?下午

            

            Console.WriteLine(m.ToString("yy年M月d日h时m分s秒"));//  14年8月20日4时5分32秒 

            

            Console.WriteLine(m.Year );//提取当前的年份  同理有月份month day hour minute second millisecond毫秒

           

            Console.WriteLine(m.DayOfWeek);//显示今天是星期几

          

            Console.WriteLine(m.DayOfYear);//显示今天是今年的第多少天

            */

 

 

 

            /*

            DateTime m = DateTime.Now;

            Console.WriteLine(m.ToLongDateString());  //显示  2014年8月20 星期三

            Console.WriteLine(m.ToShortDateString());  //显示   2014/8/20 星期三

            Console.WriteLine(m.ToLongTimeString());//显示  下午 6:51:54

            Console.WriteLine(m.ToShortTimeString());//显示  下午 6:51

            */

 

 

           /*

            //时间的加减法运算

            DateTime m = DateTime.Now;

            DateTime n = new DateTime(2001,03,02,12,11,23);

            Console.WriteLine(m-n);//结果显示你输入的日期到现在一共有多少天多少小时多少分多少秒  一共多少秒

            Console.WriteLine(n.AddDays(-100)); //结果显示比n早100天的日期和时间 也可以加改成正数即可

                                                  //同理有年,月,时,分,秒,毫秒的 加减

             */

 

 

           

            /*

            double a = 10, b = 3, c = a / b;

            Console.WriteLine(c.ToString("#.##"));//保留两位小数  如果能整除则不显示小数部分

            Console.WriteLine(c.ToString("0.00"));//保留两位小数 能不能整除都会保留两位小数  能整除用0补齐

             Console.WriteLine(c.ToString("#.00"));

             Console.WriteLine(c.ToString("0.##"));

            Console.WriteLine(c.ToString("#.##元"));//结果显示3.33元

            */

            /*

            double a = 1000000, b = 3, c = a / b;

            Console.WriteLine(c.ToString("#,#.##"));//结果显示333,333.33三位一个逗号自个位向左数

            */

 

 

            //数字方面的值

            /*

            Console.WriteLine(Math.Abs(-34.23));//求绝对值   34.23

            Console.WriteLine(Math.Ceiling (4.3));//取顶数  5  例如取页数没有半页的,往上捐

            Console.WriteLine(Math.Floor (4.3));//取底数    4 

            Console.WriteLine(Math.Round (4.3));//四舍五入  4

            Console.WriteLine(Math.Round (4.8));//四舍五入  5

            Console.WriteLine(Math.Sqrt (9));//开方求根   3

            */

 

 

 

//判断是平年还是闰年

            /*

            Console.Write("输入年份:");

            int i=Convert .ToInt32(Console.ReadLine());

            if (i >= 1 && i <= 9999)

            {

                if (i % 400 == 0 || i % 4 == 0 && i % 100 != 0)

                {

                    Console.WriteLine(i + "是闰年");

                }

                else

                {

                    Console.WriteLine(i + "是平年");

                }

            }

            else

            {

                Console.WriteLine("您输入的数值无意义");

            }

 

            */

 

 

            //判断日期是否正确

            /*

            Console.Write("输入年份");

            int i = Convert.ToInt32(Console.ReadLine());

            Console.Write("输入月份");

            int m = Convert.ToInt32(Console.ReadLine());

            Console.Write("输入日期");

            int n = Convert.ToInt32(Console.ReadLine());

 

 

 

            if (i >= 1 && i <= 9999)

            {

                if (i % 400 == 0 || i % 4 == 0 && i % 100 != 0)

                {

                    if(m>=1&&m<=12)

                    {

                        if (n >= 1 && n <= 31 && (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12))

                        {

                            Console.WriteLine("您输入的日期正确");

                        }

                        else if(n>=1&&n<=30&&(m==4||m==6||m==9||m==11))

                        {

                            Console.WriteLine("您输入的日期正确");

                        }

                        else if (n >= 1 && n <= 29)

                        {

                            Console.WriteLine("您输入的日期正确");

                        }

                        else

                        {

                            Console.WriteLine("您输入的数值无意义");

                        }

                    }

                    else

                    {

                        Console.WriteLine("您输入的数值无意义");

                    }

 

 

                }

                else

                {

                    if (m >= 1 && m <= 12)

                    {

                        if (n >= 1 && n <= 31 && (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12))

                        {

                            Console.WriteLine("您输入的日期正确");

                        }

                        else if (n >= 1 && n <= 30 && (m == 4 || m == 6 || m == 9 || m == 11))

                        {

                            Console.WriteLine("您输入的日期正确");

                        }

                        else if (n >= 1 && n <= 28)

                        {

                            Console.WriteLine("您输入的日期正确");

                        }

                        else

                        {

                            Console.WriteLine("您输入的数值无意义");

                        }

                   
}

                    else

                    {

                        Console.WriteLine("您输入的数值无意义");

                    }

                }

            }

            else

            {

                Console.WriteLine("您输入的数值无意义");

            }

 

           

            */

 

 

            //截取身份证号码的出生日期

           /*

 

             Console.WriteLine("请输入身份证号:");

             string i = Convert.ToString(Console.ReadLine());

                if(i.Length==18)

                {

                    Console.WriteLine(i.Substring (6,8));

                }

               else

            {

                 Console.WriteLine("您输入的数值无意义");

            }

          */

 

 

 

//随机验证码的生成  可应用于缘分测试

       /*

            string s = "1234567890qwertyuiopasdfghjklzxcbvnmQWERTYUIOPASDFGHJKLZXCVBNM";

            string m="";

                Random  aaa=new Random();

                for (int i = 1; i < 5; i++)

                {

                    int n = aaa.Next(s.Length );

                    m = m + s.Substring(n,1);

                }

                Console.WriteLine(m);

            */

           

 

            /*生成的是一个字符 出现四次

            string s = "1234567890qwertyuiopasdfghjklzxcbvnmQWERTYUIOPASDFGHJKLZXCVBNM";

            string m = "";

          

            for (int i = 1; i < 5; i++)

            {

                Random aaa = new Random();

                int n = aaa.Next(s.Length);

                m = m + s.Substring(n, 1);

            }

            Console.WriteLine(m);

            */

 

 

            /*每个种子都有永久不变的字符

            string s = "1234567890qwertyuiopasdfghjklzxcbvnmQWERTYUIOPASDFGHJKLZXCVBNM";

            string m = "";

            Random aaa = new Random(4);//可输入种子,种种子后随机数不变,没有种子没有随机数,不写种子系统按时间计算

            for (int i = 1; i < 5; i++)

            {

                int n = aaa.Next(s.Length);

                m = m + s.Substring(n, 1);

            }

            Console.WriteLine(m);

 

            */

 

Console.Write("输入邮箱:");

            string s = Console.ReadLine();

            bool m=s.StartsWith(" ");

            bool n=s.StartsWith(".");

            int a = s.IndexOf("@");

            int c = s.LastIndexOf("@");

            bool b = s.Contains(".");

            bool d = s.Contains("..");

            if (m == n == d == false && a != 0 && a != c && b == true)

            {

                Console.WriteLine("登录成功");

            }

            else

                Console.WriteLine("您输入的邮箱错误");