我正在做一个子字符串比较,我这样做了
if ([mystring rangeOfString:string options:NSCaseInsensitiveSearch].location == NSNotFound) {
return NO;
} else {
return YES;
}
但这在与 Read 和 READ 比较时不起作用
抱歉,但是您的代码对我有用...如果我在 XCode 中执行此操作:
if ([@"Read" rangeOfString:@"READ" options:NSCaseInsensitiveSearch].location == NSNotFound) {
NSLog(@"NO!!");
} else {
NSLog(@"YES!!");
}
我得到这个输出:
YES!!
它会工作,试试这个
NSString *str = @"Read";
NString *matchStr = @"READ";
if ([[str lowercaseString] rangeOfString:[matchStr lowercaseString] ].location == NSNotFound) {
NSLog(@"NO!!");
} else {
NSLog(@"YES!!");
}