NSString *str1 = @"abc"; // a 97
NSString *str2 = @"abc"; // A 65
//取出每个字符的ASCII码值 ,比较ASCII码值大小
//compare方法比较大小
//compare 默认的区分大小写的
//compare 这个函数,不能增加条件
// NSComparisonResult result = [str1 compare:str2];
//比较的时候,不区分大小写,参考字符的个数
NSComparisonResult result = [str1 compare:str2 options:NSCaseInsensitiveSearch|NSNumericSearch];
//
switch (result) {
case NSOrderedAscending:
NSLog(@"str1 < str2 升序");
break;
case NSOrderedDescending:
NSLog(@"str1 > str2 降序");
break;
case NSOrderedSame:
NSLog(@"str1 == str2 ");
break;
default:
break;
} |
|