Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
range.location 应该是 0。我说得对吗?
NSRange range; range = [@"beer" rangeOfString:@"beer and vodka"]; if (range.location== NSNotFound) { NSLog(@"Why?"); }
因为您在“beer”字符串中搜索字符串“beer and vodka” - 很明显,较短的字符串中不存在较长的字符串,因此您会得到预期的输出。您需要的可能反之亦然:
NSRange range = [@"beer and vodka" rangeOfString:@"beer"]; if (range.location == NSNotFound) { NSLog(@"Why?"); }