2
range.location應該是0.我是對的嗎?NSRange:不正確的行爲。爲什麼?
NSRange range;
range = [@"beer" rangeOfString:@"beer and vodka"];
if (range.location== NSNotFound)
{
NSLog(@"Why?");
}
range.location應該是0.我是對的嗎?NSRange:不正確的行爲。爲什麼?
NSRange range;
range = [@"beer" rangeOfString:@"beer and vodka"];
if (range.location== NSNotFound)
{
NSLog(@"Why?");
}
因爲您搜索「啤酒」字符串的字符串「啤酒和伏特加」 - 顯然,較長的字符串是不存在的短的,所以你得到預期的輸出。您需要的東西應該反過來:
NSRange range = [@"beer and vodka" rangeOfString:@"beer"];
if (range.location == NSNotFound)
{
NSLog(@"Why?");
}