NSString *tmp1 = @"";
if (tmp1 == nil || tmp1.length == 0) {
NSLog(@"字符串为空");
}
NSString *tmp2 = @"www.bk.com";
BOOL prefix = [tmp2 hasPrefix:@"www"];
NSLog(@"%@",prefix ? @"YES" : @"NO");
NSString *tmp3 = @"www.bk.txt";
BOOL suffix = [tmp3 hasSuffix:@"txt"];
NSLog(@"%@",suffix ? @"YES" : @"NO");
NSString *str = @"abc";
NSString *str1 = @"abc";
if (str == str1) {
NSLog(@"相等");
}
NSString *str2 = [NSString stringWithFormat:@"%@",@"abc"];
BOOL isEqual1 = [str isEqualToString:str2];
NSLog(@"isEqualToString %@",isEqual1 ? @"YES" : @"NO");
BOOL isEqual2 = [str myIsEqual:str2];
NSLog(@"myIsEqual %@",isEqual2 ? @"YES" : @"NO");
NSComparisonResult compare = [str compare:str1];
NSLog(@"%ld",compare);
switch (compare) {
case NSOrderedAscending:
NSLog(@"NSOrderedAscending");
break;
case NSOrderedSame:
NSLog(@"相等");
break;
case NSOrderedDescending:
NSLog(@"NSOrderedDescending");
break;
default:
break;
}
}