如何从
中提取NSUInteger index
NSRange range = [string rangeOfString: substring]
所以我可以在[array objectAtIndex:index]
?
答案 0 :(得分:3)
NSRange range = [string rangeOfString:substring];
NSUInteger index = range.location;
//...
答案 1 :(得分:3)
// make sure that the substring was actually found:
NSRange result = [string rangeOfString:substring];
if (result.location != NSNotFound)
{
// make sure that the index exists in the array
if (result.location < [array count])
{
id someObj = [array objectAtIndex:result.location];
// do something cool with someObj here
}
}