• 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();
            }
        }
    }

  • 相关阅读:
    被@ResponseBoby注释的方法在拦截器的posthandle方法中设置cookie失效的问题
    python之异常处理
    python之url编码
    python之发送邮件
    python之使用request模块发送post和get请求
    python之小技巧积累
    python之sys.argv[]
    python之MD5加密
    python之os、sys和random模块
    python之time和datetime的常用方法
  • 原文地址:https://www.cnblogs.com/jakeasd/p/5344465.html
Copyright © 2020-2023  润新知