• 140821 字符串,数字,日期及应用举例


    brerk   彻底终断循环,跳出for语句

    continue 中断当前循环,进行下一循环

    s.Length            s的长度
     
     
     
    s.Trim()             去除两边空格
     
    s.TrimStart()        去除前面的空格
     
    s.TrimEnd()           去除后面的空格
     
     
     
    s.ToUpper()        字母变大写
     
    s.ToLower()        字母变小写
     
     
     
    s.Substring()      1.截取位置到最后  2.(截取位置,长度)
     
     
     
    s.StartsWith()     判断字符串开头是否匹配
     
    s.EndsWith()      判断字符串末尾是否匹配
     
    s.Contains()     中间
     
     
     
    s.IndexOf()        从前面数第一次出现的位置
     
    s.LastIndexOf()    从后面数第一次出现的位置
     
     
     
    s.Replace()         替换

    例子:

              //判断日期是否正确

                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("输入错误");

                }

     

    //判断邮箱

    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("yes");

                }

                else

                    Console.WriteLine("not");

  • 相关阅读:
    [转贴]USB簡介
    [网游计划第六、七天]压力好大,坚持很难
    [备忘] 字符串倒序函数strrev
    我的网游计划:ACM 30天 60题
    [网游计划第一天]:不怎么顺利的开始
    程序员必须要有的自信
    转:squid做反向代理时,要注意的安全设置
    Linux DHCP Server 配置给FIT AP 使用的option
    jdk配置
    nod32升级
  • 原文地址:https://www.cnblogs.com/jackjms/p/3929333.html
Copyright © 2020-2023  润新知