Objective-C rangeOfString tomonidan qaytarilgan qator oralig'ini chiqaradi:

Qanday qilib NSUInteger indeksini -dan chiqarish mumkin

NSRange range = [string rangeOfString: substring]

shuning uchun bu indeksni [array objectAtIndex: index] da yozishingiz mumkin?

2

2 javoblar

// 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
    }
}
3
qo'shib qo'ydi
NSRange range = [string rangeOfString:substring];
NSUInteger index = range.location;
//...
3
qo'shib qo'ydi
ifodali satr bu satrning boshida topilgan bo'lsa, intervalli.location juda katta sonni qaytaradi. Nima uchun bu?
qo'shib qo'ydi muallif coolcool1994, manba
@ coolcool1994 sababini topdingizmi? Men bir xil muammolarga duch kelmoqdaman
qo'shib qo'ydi muallif hoangpx, manba