标签:
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
//比较两个字符串大小
NSString *str=[[NSString alloc]initWithString:@"a"];
NSString *str1=[[NSString alloc]initWithString:@"A"];
NSComparisonResult result= [str compare:str1];
// NSComparisonResult result= [str caseInsensitiveCompare:str1];
if (result==NSOrderedAscending) {
NSLog(@"str<str1");
}else if (result==NSOrderedDescending){
NSLog(@"str>str1");
}else{
NSLog(@"str=str1");
}
/*2.比较两个字符串内容是否相同
if (str==str1) {
NSLog(@"两个字符串内容相同");
}else{
NSLog(@"两个字符串内容不相同");
}
*/
/* //1.比较字符串对象是否相同
if ([str isEqualToString:str1]){
NSLog(@"两个字符串相同");
}else{
NSLog(@"两个字符串不相同");
}
*/
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/jidezhi/p/5120702.html