2011-09-09 130 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 = [[array objectAtIndex:0] intValue] * 24 * 60 + [[array objectAtIndex :2] intValue] * 60 + [[array objectAtIndex:4] intValue]; – Prabh

+0

哦,我的錯誤,感謝您的評論 – Robin