How do I check if a string contains another string in Objective-C?

前端 未结 23 2011

How can I check if a string (NSString) contains another smaller string?

I was hoping for something like:

NSString *string = @\"hello bla         


        
23条回答
  •  無奈伤痛
    2020-11-22 15:17

    Since this seems to be a high-ranking result in Google, I want to add this:

    iOS 8 and OS X 10.10 add the containsString: method to NSString. An updated version of Dave DeLong's example for those systems:

    NSString *string = @"hello bla bla";
    if ([string containsString:@"bla"]) {
        NSLog(@"string contains bla!");
    } else {
        NSLog(@"string does not contain bla");
    }
    

提交回复
热议问题