Lochana Ragupathy
Lochana Ragupathy

Reputation: 4320

NSCaseInSensitive in ios

I am making a substring comparison and i did it like this

 if ([mystring rangeOfString:string options:NSCaseInsensitiveSearch].location == NSNotFound) {
        return NO;
    } else {
        return YES;
    }

But this doesn't work while comparing with Read and READ

Upvotes: 1

Views: 111

Answers (2)

SachinVsSachin
SachinVsSachin

Reputation: 6427

It will work, try this

NSString *str = @"Read";
NString *matchStr = @"READ";

if ([[str lowercaseString] rangeOfString:[matchStr lowercaseString] ].location == NSNotFound) {
NSLog(@"NO!!");
} else {
NSLog(@"YES!!");
}

Upvotes: 1

Tom van Zummeren
Tom van Zummeren

Reputation: 9220

Sorry, but your code works for me... If I execute this in XCode:

if ([@"Read" rangeOfString:@"READ" options:NSCaseInsensitiveSearch].location == NSNotFound) {
    NSLog(@"NO!!");
} else {
    NSLog(@"YES!!");
}

I get this output:

YES!!

Upvotes: 2

Related Questions