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

  • 相关阅读:
    [daily][archlinux][shell][fish] 使用最炫酷的shell工具fish
    [daily][btrfs][mlocate][updatedb] mlocate不认识btrfs里面的文件
    [daily][archlinux] TODO LIST
    [math][mathematica] mathematica入门
    [math][mathematica] archlinux 下 mathematica 的安装 (科学计算软件 mathematica/matlab/sagemath)
    [daily][centos][sudo] sudo 报错
    [development][C][thread_local] 线程全局变量
    [development][C] C语言标准
    [daily][centos][nginx] 在centos7使用nginx启用对文件目录的http访问
    CS RANK: AI & ML
  • 原文地址:https://www.cnblogs.com/jackjms/p/3929333.html
Copyright © 2011-2022 走看看