Nik's
Nik's

Reputation: 690

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

Basically 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

Upvotes: 0

Views: 87

Answers (1)

Robin
Robin

Reputation: 10011

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];

Upvotes: 1

Related Questions