zoukankan      html  css  js  c++  java
  • 2017-02-26

    +++++String类+++++
    黑色小扳手 - 属性
    紫色立方体 - 方法


    ***字符串.Length  -  字符串长度,返回int类型

    字符串.TrimStart() - 去掉前空格
    字符串.TrimEnd() - 去掉后空格
    ***字符串.Trim() - 去掉字符串的前后空格  string

    ***字符串.ToUpper() - 将字符串中的小写字符变成大写 string
    ***字符串.ToLower() - 变成小写 string

    索引/下标
    ***字符串.SubString(a); - 截取字符串,a - 要开始截取的下标,包含下标所对应的字符
    ***字符串.SubString(a,b); - a - 下标 , b - 要截取几个字符(从1开始数)
    string

    注意:????

    ***字符串.IndexOf("串"); - 返回字符串中第一个匹配项的索引,如果没有匹配项返回-1  int
    int b = s.IndexOf("天",s.IndexOf("天")+1); //获得第二个匹配项,3 4 5 6

    字符串.LastIndexOf("串"); - 返回最后一个匹配项的索引

    ***字符串.StartWith("串"); - 判断是否以什么开头
    ***字符串.EndsWith("串"); - 判断是否以什么结尾
    ******字符串.Contains("串"); - 判断是否包含   string

    ****s.Replace(要替换的字符串, 替换的字符串); - 字符替换  string
    s.Remove(3);  - 移除从索引到末尾的全部字符  string












    +++++Math类+++++
    Math.Pow(x,y);
    Math.Sqrt(x);

    Math.Ceiling(double);
    Math.Floor(double);
    Math.Round(double);
    Math.Abs(double);

    +++++DateTime类+++++
    DateTime 变量名 = new DateTime();

    DateTime.Now;

    .ToString("Format");

    .AddYears();
    .AddMonths();
    .AddDays();
    .AddHours();
    .AddMinutes();
    .AddSeconds();

    .Year;
    .Month;
    .Day;
    .Hour;
    .Minute;
    .Second;
    .Millisecond;

    .DayOfYear;
    .DayOfWeek;

    .Date;
    .TimeOfDay;

    TimeSpan类型
    .Days
    .Hou
    .Minutes
    .Seconds
    .Milliseconds

    .Total....

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace 练习_邮箱验证
    {
        class Program
        {
            static void Main(string[] args)
            {
                while (true)
                {
    
                    //1-“邮箱正确!/错误!”    string 放置最终结果
                    string end = "邮箱正确!";
                    //2-“只能有一个@符号”      bool
                    bool atOnlyOne = true;
                    //3-“不能以@开头”          bool
                    bool atStart = true;
                    //4-“不能以@结尾”          bool
                    bool atEnd = true;
                    //5-“@之后必须有点”        bool
                    bool atDian = true;
                    //6-“@之后不能是点”         bool
                    bool atNoDian = true;
                    //7-最少一个点,最多两个点   
                    bool dianOneOrTwo = true;
                    //8-“不能以点结尾”
                    bool dianEnd = true;
                    //9-不能以数字结束
                    bool NumEnd = true;
    
                    //一、让用户输入邮箱
                    Console.Write("请输入您的邮箱地址:");
                    string user_mail = Console.ReadLine();
    
                    if (user_mail.Length > 0)
                    {
                        #region 是否只有一个@符号
                        int a1 = user_mail.IndexOf("@");
    
                        if (a1 == -1)
                        {
                            atOnlyOne = false;
                            end = "邮箱格式错误!";
                        }
                        else
                        {
                            int a2 = user_mail.IndexOf("@", a1 + 1);
                            if (a2 != -1)
                            {
                                atOnlyOne = false;
                                end = "邮箱格式错误!";
                            }
                        }
                        #endregion
    
                        #region 判断是否以@开头
                        if (user_mail.StartsWith("@"))
                        {
                            atStart = false;
                            end = "邮箱格式错误!";
                        }
                        #endregion
    
                        #region 判断是否以@结尾
                        if (user_mail.EndsWith("@"))
                        {
                            atEnd = false;
                            end = "邮箱格式错误!";
                        }
                        #endregion
    
                        #region 判断@之后有没有点,判断如果有点,是不是超过两个
                        string a3 = user_mail.Substring(user_mail.IndexOf("@"));
                        int a4 = a3.IndexOf(".");
                        if (a4 == -1)
                        {
                            atDian = false;
                            end = "邮箱格式错误!";
                        }
                        else
                        {
                            //@sina.com.cn
                            int a6 = 1; //记录点的个数
                            int a5 = a3.IndexOf("."); //获取第一个点的索引
    
                            while (true)
                            {
                                a5 = a3.IndexOf(".", a5 + 1);//持续往后找点
                                if (a5 != -1)
                                    a6++;
                                else
                                    break;
                            }
    
                            if (a6 > 2)
                            {
                                dianOneOrTwo = false;
                                end = "邮箱格式错误!";
                            }
                        }
                        #endregion
    
                        #region @之后不能是点
                        if (user_mail.IndexOf("@.") != -1)
                        {
                            atNoDian = false;
                            end = "邮箱格式错误!";
                        }
                        #endregion
    
                        #region 不能以点结尾
                        if (user_mail.EndsWith(".") == true)
                        {
                            dianEnd = false;
                            end = "邮箱格式错误!";
                        }
                        #endregion
    
                        #region 不能以数字结束
                        string a10 = user_mail.Substring(user_mail.Length - 1, 1);
                        try
                        {
                            Convert.ToInt32(a10);
                            NumEnd = false;
                            end = "邮箱格式错误!";
                        }
                        catch { }
                        #endregion
    
                        #region 打印结果
                        //打印结果!!!
                        if (atOnlyOne == false)
                            Console.WriteLine("只能有一个@符号");
                        if (atStart == false)
                            Console.WriteLine("不能以@开头");
                        if (atEnd == false)
                            Console.WriteLine("不能以@结尾");
                        if (atDian == false)
                            Console.WriteLine("@之后必须有点");
                        if (atNoDian == false)
                            Console.WriteLine("@之后不能是点");
                        if (dianOneOrTwo == false)
                            Console.WriteLine("最少一个点,最多两个点");
                        if (dianEnd == false)
                            Console.WriteLine("不能以点结尾");
                        if (NumEnd == false)
                            Console.WriteLine("不能以数字结束");
    
                        Console.WriteLine(end);
                        #endregion
                    }
                    else
                    {
                        Console.WriteLine("邮箱不能为空!");
                    }
    
    
                    Console.ReadKey();
                }
            }
        }
    youxiang
    邮箱习题
     
  • 相关阅读:
    转-iOS开发系列--地图与定位
    转-关于UIView的autoresizingMask属性的研究
    UIAlertController的使用,代替UIAlertView和UIActionSheet
    设置当前导航栏(navigationController)的标题
    tabBar隐藏方式
    ubuntu 安装qq 及解决安装完搜狗输入法不显示键盘的方法
    python 读写文件
    Ubuntu:如何显示系统托盘图标(systray)
    python tesseract 识别图片中的文字的乱码问题(ubuntu系统下)
    让Ubuntu可以压缩/解压缩RAR文件
  • 原文地址:https://www.cnblogs.com/changxiaosen/p/6475819.html
Copyright © 2011-2022 走看看