2011-09-09 6 views
0

아래에 표시된 것처럼 문자열에 텍스트가 있습니다.한 단위로 나누는 방법

NSString *total_duration= 2 days 5 hours 6 min 

기본적으로 각 장치는 분 단위로 하나씩 표시됩니다. 이

NSInteger *total_duration_inMin=2*24*60+5*60+6 
를 어떻게 얻을 수 있습니까?
+0

수있는 최대 기간이 있습니까? – Madhu

+0

@ Madhumal Gunetileke nops하지만 거리만으로도 시간과 분만 가능합니다 .... –

답변

1

모든 시간을 얻을 수 있습니다 당신이 사용할 수있는이

NSArray *array = [total_duration componentsSeparatedByString:@" "]; 

NSInteger a = [[array objectAtIndex:0] intValue] * 24 * 60 + [[array objectAtIndex:2] intValue] * 60 + [[array objectAtIndex:4] intValue]; 
+0

약간의 수정 : NSInteger a = [[배열 objectAtIndex : 0] intValue] * 24 * 60 + [[배열 objectAtIndex : 2] intValue] * 60 + [[배열 objectAtIndex : 4] intValue]; – Prabh

+0

오, 내 실수, 코멘트 주셔서 감사합니다 – Robin

관련 문제