"字符串",//返回0时,相等,//返回-1时 "字符串">MyString string MyString = "Hello World!"; Console.WriteLine(Strin_字符串比较">
赞
踩
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'));
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。