#import <Foundation/Foundation.h>
void test(){
NSString *str = @"abc";
NSString *str1 = @"aBc";
//options:NSCaseInsensitiveSearch|NSNumericSearch 加上就不区分大小写
NSComparisonResult result = [str compare:str1 options:NSCaseInsensitiveSearch|NSNumericSearch];
switch (result) {
case NSOrderedAscending:
NSLog(@"升序str < str1");
break;
case NSOrderedSame:
NSLog(@"相等str == str1");
break;
case NSOrderedDescending:
NSLog(@"降序str > str1");
break;
default:
break;
}
}
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSString *str1 = @"abc";//在常量区
NSString *str2 = [NSString stringWithFormat:@"aBc"];//在堆区
NSLog(@"%p,%p",str1,str2);
BOOL isYes = [str2 isEqualToString:str1];
if (isYes) {
NSLog(@"str1 = str2");
}else{
NSLog(@"str1 != str2");
}
}
return 0;
} |
|