-1

NSString *word = @"明天是星期一选白车";

我想检查字符串是否有“select”和“car”然后我想得到汽车的颜色。在这里用户可以写“选择蓝色汽车”“选择红色汽车”,我只想在检查字符串是否有选择和汽车后获取颜色。谢谢

4

3 回答 3

1

只需检查单词@"select"是否在字符串中,如果是,则获取子字符串。

if([word rangeOfString:@"select"].location != NSNotFound){
  // Grab the next substring after the word @"select";
}

希望有帮助!

于 2013-10-02T21:30:42.687 回答
0
NSString *word = @"Tomorrow is monday select white car";
if (([word rangeOfString:@"select"].location)&& ([word rangeOfString:@"car"].location)  != NSNotFound ) {
    NSLog(@"string contains select and car!");
} else {
    NSLog(@"string does not contain select and car!");
}
于 2014-08-01T09:17:13.703 回答
0

用这个

if([string1 rangeOfString:@"select"].location != NSNotFound && [string1 rangeOfString:@"car"].location){

NSLog(@"select and car found");  
于 2013-10-03T04:46:02.863 回答