Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find one string in another with case insensitive in Objective-C

My question is similar to How do I check if a string contains another string in Objective-C?

How can I check if a string (NSString) contains another smaller string but with ignoring case?

NSString *string = @"hello bla bla"; 

I was hoping for something like:

NSLog(@"%d",[string containsSubstring:@"BLA"]); 

Anyway is there any way to find if a string contains another string with ignore case ? But please do not convert both strings to UpperCase or to LowerCase.

like image 302
Jim Avatar asked Feb 13 '12 10:02

Jim


1 Answers

As similar to the answer provided in the link, but use options.

See - (NSRange)rangeOfString:(NSString *)aString options:(NSStringCompareOptions)mask in Apple doc

NSString *string = @"hello bla bla";  if ([string rangeOfString:@"BLA" options:NSCaseInsensitiveSearch].location == NSNotFound) {     NSLog(@"string does not contain bla"); }  else  {     NSLog(@"string contains bla!"); } 
like image 151
Ilanchezhian Avatar answered Oct 07 '22 18:10

Ilanchezhian