zoukankan      html  css  js  c++  java
  • 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");

  • 相关阅读:
    参考阿里规范,优秀的 Java 项目代码该如何分层?
    SpringBoot 中实现跨域的5种方式
    美团一面:你既然写过Mybatis插件,说说它底层是怎么加载一个自定义插件的
    陌陌面试官:说说Spring AOP 的原理、SpringMVC 的处理过程?
    这16条规范代码,同事,拍桌子 大喊 “666”
    微服务很简单,用一张架构图了解一下
    K8S部署Metrics-Server服务
    cookie
    html标签默认样式整理
    html 语义化标签
  • 原文地址:https://www.cnblogs.com/jackjms/p/3929333.html
Copyright © 2011-2022 走看看