Detecting if an NSString contains…?

后端 未结 7 2214
长情又很酷
长情又很酷 2021-01-30 03:37

How can I detect if a string contains a certain word? For example, I have a string below which reads:

@\"Here is my string.\"

I\'d like to know

7条回答
  •  南笙
    南笙 (楼主)
    2021-01-30 04:13

    Use the following code to scan the word in sentence.

    NSString *sentence = @"The quick brown fox";
    NSString *word = @"quack";
    if ([sentence rangeOfString:word].location != NSNotFound) {
        NSLog(@"Yes it does contain that word");
    }
    

提交回复
热议问题