码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-08-22 15:48:08      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:os   for   ar   art   amp   line   sp   ad   on   

 

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

 

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

标签:os   for   ar   art   amp   line   sp   ad   on   

原文地址:http://www.cnblogs.com/jackjms/p/3929333.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!