2011-10-27 3 views
2

어떻게목표 - C 추출물 지수 :

NSRange range = [string rangeOfString: substring] 

그래서 난 [array objectAtIndex:index]이 인덱스를 작성할 수 NSUInteger index에서 추출하는? 그 문자열은 해당 문자열의 길의 시작에서 발견되는 경우

답변

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 
    } 
} 
3
NSRange range = [string rangeOfString:substring]; 
NSUInteger index = range.location; 
//... 
+0

range.location는 정말 큰 수를 반환합니다. 왜 이런거야? – coolcool1994

+0

@ coolcool1994 이유를 찾았습니까? 나는 똑같은 문제를 겪고있다. – hoangpx