• 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: Prepending to fixed length
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Prepending to fixed length


  • Subject: Re: Prepending to fixed length
  • From: "stephen joseph butler" <email@hidden>
  • Date: Tue, 18 Jul 2006 17:00:34 -0500

>> I have an int that I want converted into a string but I want it
>> prefixed
>> with zeros to a fixed length. So.
>>
>> 1 = 00001
>> 2 = 00002
>>
>> 534 = 00534
>
> NSString *foo = [NSString stringWithFormat:@"]", aSignedInt];

This results in strings like " 8" instead of "08".

It should really be:

NSString *foo = [NSString stringWithFormat:@"d", aSignedInt];

Otherwise it pads with spaces. For more on the format, look at:

http://developer.apple.com/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html#//apple_ref/doc/uid/TP40004265-SW1

and "man 3 printf" from a terminal window.
_______________________________________________
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


References: 
 >Re: Prepending to fixed length (From: Sherm Pendley <email@hidden>)
 >Re: Prepending to fixed length (From: Trygve Inda <email@hidden>)

  • Prev by Date: Re: Prepending to fixed length
  • Next by Date: Re: Prepending to fixed length
  • Previous by thread: Re: Prepending to fixed length
  • Next by thread: Re: Prepending to fixed length
  • Index(es):
    • Date
    • Thread