c#字符串处理

来源:互联网 发布:苹果手机视频导入mac 编辑:程序博客网 时间:2024/05/16 20:27

 public void cl_string(string con="abcdeftg") {
    //split   //拆分字符串
        string[] val= con.Split('$');
   
   //replate //替换字符串
       string val_replate = con.Replace("$",".");
  
   //substring截取字符串
       string val_substring = con.Substring(3, 4);

    //contains查看指点字符是不是在字符串中出现
       bool val_contains = con.Contains("de");

    //endwith查看是不是以指点字符结尾
       bool val_endwith = con.EndsWith("f");

    //startswith 查看是不是以指定字符开头
       bool val_startswith = con.StartsWith("as");
       
    //indexof查看指定字符在字符串中的位置,未找到返回-1
       int val_indexof = con.IndexOf("a");

    //lastindexof查看字符在字符串中最后出现的位置未找到返回-1
       int val_lastindexof = con.LastIndexOf("e");


    //padleft补充字符串以实现指定长度,不够从左补充指定字符
       string val_padleft = con.PadLeft(20, '.');

    //padright补充字符串以实现指定长度,不够从右补充指定字符
       string val_s = con.PadRight(20,'.');

    }

原创粉丝点击