I have a NSString like this.
00:03:45
I want to get only this 03:45 part and show in a UILabel
How can I do that? Please help me
Thanks
I have a NSString like this.
00:03:45
I want to get only this 03:45 part and show in a UILabel
How can I do that? Please help me
Thanks
NSArray *timeParts = [string componentsSeparatedByString: @":"];
NSString *newTime = [NSString stringWithFormat:@"%@/%@", [timeParts objectAtIndex:1], [timeParts objectAtIndex:2]];
Don't think in terms of splitting a string, think in terms of formatting your date that happens to be a string. You'll want to use an NSDateFormatter here.
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"mm:ss"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0.0]];//Or whatever is applicable for your
NSString *timeString = [self.dateFormatter dateFromString:[NSDate dateFromString:yourString];
Or, if you really wanted to get a substring from that particular string, you could do this:
NSString *subString = [yourString substringWithRange:NSMakeRange(3, 7)];
you can do this multiple types
assume that this is your String
NSString *origialString =@"00:03:45";
Type-1
NSArray *getBalance = [origialString componentsSeparatedByString: @":"];
origialString = [NSString stringWithFormat:@"%@:%@", [getBalance objectAtIndex:1], [getBalance objectAtIndex:2]];
Type-2
origialString = [origialString substringFromIndex:3];
Type-3
origialString = [origialString substringWithRange:NSMakeRange(3, [origialString length]-3)];
Type-4
// Use NSDateformatter but not necessary for here