1, indexof()获取字符在字符串当中的索引值,如果找到了返回对应的索引值,如果返回-1,那么就找不到
string str = "abcdefgabc"; Console.WriteLine(str.IndexOf("a"));//0 Console.WriteLine(str.IndexOf("h"));//-1 Console.WriteLine(str.IndexOf("bc"));//1 Console.WriteLine(str.IndexOf('f', 4));//5 从参数2地方开始搜索参数12, /2 LastIndexOf 从后往前找,找出第一个与之匹配的字符
string str = "abcdefgabc"; Console.WriteLine(str.LastIndexOf("a"));//73,IndexOfAny()从数组范围中,找到任何一个对应的索引值(找到一个就停)
string str = "abcdefgabc"; Console.WriteLine(str.IndexOfAny(new char[] { 'c', 'b', 'a' }));//04,Contains() 是否包含参数
string str = "abcdefgabc"; Console.WriteLine(str.Contains("fg"));//true Console.WriteLine(str.Contains("he"));//false5,ToUpper()把字符转成大写的,ToLower()把字符转成小写的
string str = "abcdefgabc"; Console.WriteLine(str.ToUpper());//ABCDEFGABC Console.WriteLine(str.ToLower());//abcdefgabc6,StartsWith() 判断字符串是否以参数开头的
string str1 = "qwerdf"; Console.WriteLine(str1.StartsWith("qwe"));//true7,EndsWith() 判断是不是以。。。结尾
Console.WriteLine(str1.EndsWith("df"));//true8,IsNullOrEmpty() 判断字符串是不是null或者是空字符串
string str2 = ""; Console.WriteLine(string.IsNullOrEmpty(str2));//true str2 = null;//空的 Console.WriteLine(string.IsNullOrEmpty(str2));//true str2 = " ";//空格字符串 Console.WriteLine(string.IsNullOrEmpty(str2));//false9,Equals()判断两个字符是否相等 object比较不要用==,使用Equals
string str = "abcdefgabc"; string str1 = "qwerdf"; Console.WriteLine(string.Equals(str, str1));//false10,join()把指定的分割符号添加到对应的字符串之间
string str1 = "qwerdf"; Console.WriteLine(string.Join("-", str1, "sss"));//qwerdf-sss