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

后端 未结 5 2131
慢半拍i
慢半拍i 2021-02-11 17:24

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 w

5条回答
  •  梦如初夏
    2021-02-11 17:55

    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!");
    }
    

提交回复
热议问题