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

前端 未结 23 2045

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:22

    Please use this code

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

提交回复
热议问题