Re: Formatting integer value
Re: Formatting integer value
- Subject: Re: Formatting integer value
- From: Andy Armstrong <email@hidden>
- Date: Mon, 14 Feb 2005 13:44:37 +0000
On 14 Feb 2005, at 13:39, Sherm Pendley wrote:
You can extract substrings using NSString's -substringWithRange:
method. This example assumes that seconds are always two digits
(zero-padded if necessary), and milliseconds are always three digits.
Based on your description of the output you need, it also assumes that
325 means 3 minutes, 25 seconds, not 325 seconds. Minutes can be any
number of digits, or missing entirely.
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString *time = @"325407";
NSRange theRange = { [time length]-3, 3 };
NSString *milliseconds = [time substringWithRange:theRange];
theRange.location = [time length]-5;
theRange.length = 2;
NSString *seconds = [time substringWithRange:theRange];
theRange.location = 0;
theRange.length = [time length]-5;
NSString *minutes = [time substringWithRange:theRange];
NSLog(@"Time=%@:%@:%@", minutes, seconds, milliseconds);
[pool release];
return 0;
}
What am I missing here? Why would you do all that string manipulation
to perform simple integer arithmetic?
--
Andy Armstrong, hexten.net
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden