• 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: Need help to make this method prettier
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Need help to make this method prettier


  • Subject: Re: Need help to make this method prettier
  • From: Graff <email@hidden>
  • Date: Sat, 1 Nov 2008 15:30:06 -0400

On Nov 1, 2008, at 1:56 PM, Andre Masse wrote:

I'm implementing a custom NSFormatter. I want a number with 9 digits
displayed as "123 456 789". So before implementing the formatter I
made a test project to check the conversion. The version I did get the
job done but its not pretty :-) Any more good looking solutions?

Just a quick example:

	// get a number by any means possible
	unsigned int theNumber = 1123456789;

	// truncate numbers that are too large
	theNumber = theNumber % 1000000000;

	NSMutableString *numberString;

	// turn the number into a string padded with zeros to 9 places
	numberString = [NSMutableString stringWithFormat:@"	d", theNumber];

	// add a space character to position 6
	[numberString insertString:@" " atIndex:6];

	// add a space character to position 3
	[numberString insertString:@" " atIndex:3];

	// numberString is now formatted in the format "xxx xxx xxx"

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Need help to make this method prettier
      • From: Bill Bumgarner <email@hidden>
    • Re: Need help to make this method prettier
      • From: Andre Masse <email@hidden>
  • Prev by Date: Re: Simple Flipbook Animation?
  • Next by Date: [Q] Buttons with Menus
  • Previous by thread: Re: Need help to make this method prettier
  • Next by thread: Re: Need help to make this method prettier
  • Index(es):
    • Date
    • Thread