方法有三种:
方法一:containsString:
(iOS 8.0)
NSString *str = @"abcz";
if ([str containsString:@"Z"]) {
NSLog(@"包含");
}else {
NSLog(@"不包含");
}
------------打印结果-------------
不包含
------------小结-----------------
containsString:方法区分小写字母
方法二:localizedCaseInsensitiveContainsString:
(iOS 8.0)
NSString *str = @"abcz";
if ([str localizedCaseInsensitiveContainsString:@"Z"]) {
NSLog(@"包含");
}else {
NSLog(@"不包含");
}
------------打印结果-------------
包含
------------小结-----------------
localizedCaseInsensitiveContainsString:方法不区分小写字母
方法三:localizedStandardContainsString:
(iOS 9.0)
if ([str localizedStandardContainsString:@"Z"]) {
NSLog(@"包含");
}else {
NSLog(@"不包含");
}
------------打印结果-------------
包含
------------小结-----------------
localizedStandardContainsString:方法不区分小写字母