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

后端 未结 5 2129
慢半拍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:43

    From iOS 8 you can add the containsString: or localizedCaseInsensitiveContainsString method to NSString.

    if ([string localizedCaseInsensitiveContainsString:@"BlA"]) {
        NSLog(@"string contains Case Insensitive bla!");
    } else {
        NSLog(@"string does not contain bla");
    }
    

提交回复
热议问题