"字符串",//返回0时,相等,//返回-1时 "字符串">MyString string MyString = "Hello World!"; Console.WriteLine(Strin_字符串比较">
当前位置:   article > 正文

字符串比较大全

字符串比较

            Compare用于当前字符串对象与另外一个"字符串"进行全面比较的方法
            返回1时,MyString >"字符串",//返回0时,相等,//返回-1时 "字符串">MyString
            string MyString = "Hello World!";
            Console.WriteLine(String.Compare(MyString, "Hello Worl"));
          
            CompareTo当前字符串对象封装的字符串与另一个字符串或对象进行比较
            返回值与Compare相同
            String MyString = "Hello World";
            String OtherString = "Hello World!";
            int MyInt = MyString.CompareTo(OtherString);
            Console.WriteLine(MyInt);

            Equals轻易的确定两个字符串是否相同,区分大小写返回,True或者false
            string MyString = "Hello World";
            Console.WriteLine(MyString.Equals("Hello World"));
            string MyString = "Hello World";
            还可这样
            string YourString = "Hello World";
            Console.WriteLine(String.Equals(MyString, YourString));

            //StartsWith确定一个字符串对象是否以构成另一个字符串的同一组字符开始。返回Bool值
            //EndsWith 相反
            string MyString = "Hello World";
            Console.WriteLine(MyString.StartsWith("Hello"));

            //IndexOf确定特定字符在字符串中第一次出现的位置
            //LastIndexOf确定特定字符在字符长中最后一次出现的位置
            string MyString = "Hello World";
            Console.WriteLine(MyString.IndexOf('l')); 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/594325
推荐阅读
相关标签
  

闽ICP备14008679号