• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Formatting integer value
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Formatting integer value
      • From: Sherm Pendley <email@hidden>
References: 
 >Formatting integer value (From: RenĂ© Korthaus <email@hidden>)
 >Re: Formatting integer value (From: Sherm Pendley <email@hidden>)

  • Prev by Date: Re: Formatting integer value
  • Next by Date: Re: UDP SOCKETS!!
  • Previous by thread: Re: Formatting integer value
  • Next by thread: Re: Formatting integer value
  • Index(es):
    • Date
    • Thread