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

前端 未结 23 1744

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

    try this,

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

提交回复
热议问题