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

前端 未结 23 2024

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

    Best solution. As simple as this! If you want to find a word or part of the string. You can use this code. In this example we are going to check if the value of word contains "acter".

    NSString *word =@"find a word or character here";
    if ([word containsString:@"acter"]){
        NSLog(@"It contains acter");
    } else {
         NSLog (@"It does not contain acter");
    }
    

提交回复
热议问题