2

如何从中NSUInteger index提取

NSRange range = [string rangeOfString: substring]

所以我可以写这个索引[array objectAtIndex:index]

4

2 回答 2

3
NSRange range = [string rangeOfString:substring];
NSUInteger index = range.location;
//...
于 2011-10-27T22:07:28.087 回答
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
    }
}
于 2011-10-27T22:11:20.597 回答