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」文字列で「beerandvodka」という文字列を検索するため、短い文字列には長い文字列が存在しないため、期待どおりの出力が得られます。必要なのはおそらくその逆です。
NSRange range = [@"beer and vodka" rangeOfString:@"beer"]; if (range.location == NSNotFound) { NSLog(@"Why?"); }