开发者

how to split to get in one unit

I have the text in a string as shown below

NSString *total_duration= 2 days 5 hours 6 min

Bas开发者_如何学Cically I would like each to get in one unit like in minute. How can i get this

NSInteger *total_duration_inMin=2*24*60+5*60+6


Well if the format of your string remains same all the time then you can use this

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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜