开发者

NSRange : incorrect behavior. Why?

range.location should be 0. Am i right ?

NSRange range;
range = [@"beer" rangeOfString:@"beer an开发者_运维百科d vodka"];
if (range.location== NSNotFound)
{
    NSLog(@"Why?");
}


Because you search for a string "beer and vodka" in "beer" string - obviously that longer string is not present in the shorter one, so you get expected output. What you need should probably be vice versa:

NSRange range = [@"beer and vodka" rangeOfString:@"beer"];
if (range.location == NSNotFound)
{
    NSLog(@"Why?");
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜