C#学习(8)

字符串学习:
            l.length 字符串长度,字符串个数
             Console.WriteLine(s.Length );
             Console.WriteLine(s.TrimStart()); //去掉前面的空格
             s.TrimEnd();//去掉后边的空格
             Console.WriteLine(s.ToLower ());//转换成小写
             Console.WriteLine(s.ToUpper());//转换成大写
             bool isbaohan = s.Contains("if");//判断字符串中是否包含某字符段
             Console.WriteLine(isbaohan);
             //字符串有长度,有索引  索引从0开始到length-1结束
             int index = s.IndexOf("if",4);
             Console.WriteLine(index);
             int lastid = s.LastIndexOf("as");
             Console.WriteLine(lastid );
             string jqs = s.Substring(4,3);//(截取的索引位置,截取个数)
             Console.WriteLine(jqs); 
            

namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            //身份证号截取生日
            Console.Write("请输入身份证号:");
              string s = Console.ReadLine();
              string a = s.Substring(6, 8);
               Console.Write("你的生日是" + a);
       
          
            //从目标字符串截取第二个匹配的字符段
                string x = "fewafdfreghythdbgafdregfsdafd";
                int indes = x.IndexOf("afd");//找出第一个afd在第多少位
                Console.WriteLine("第一个afd在第"+indes+"位   ");//第一个afd的位数
                int index = x.IndexOf("afd",indes+1);//从第一个afd的f开始往后找第二个afd
                Console.Write("第二个afd在第"+index+"位   ");//打印第二个afd的位数
                string d = x.Substring(index,3);//截取第二个afd
                Console.Write(d);
              
                Console.ReadLine();
        }
    }
}

posted @ 2016-04-01 11:58  jakermk  阅读(123)  评论(0编辑  收藏  举报