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

前端 未结 23 1755

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

    Swift 4 And Above

    let str = "Hello iam midhun"
    
    if str.contains("iam") {
      //contains substring
    }
    else {
      //doesn't contain substring
    }
    

    Objective-C

    NSString *stringData = @"Hello iam midhun";
    
    if ([stringData containsString:@"iam"]) {
        //contains substring
    }
    else {
        //doesn't contain substring
    }
    

提交回复
热议问题