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

前端 未结 23 1754

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

    If do not bother about case-sensitive string. Try this once.

    NSString *string  = @"Hello World!";
    
    if([string rangeOfString:@"hello" options:NSCaseInsensitiveSearch].location !=NSNotFound)
    {
        NSLog(@"found");
    }
    else
    {
        NSLog(@"not found");
    }
    

提交回复
热议问题