Skip navigation.
 
mlRe: Prepending to fixed length
FROM : Trygve Inda
DATE : Tue Jul 18 23:54:11 2006

> On Jul 18, 2006, at 3:43 PM, Trygve Inda wrote:
>

>> 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
>>
>> Basically the opposite of
>>
>> stringByPaddingToLength:withString:startingAtIndex:
>>
>> Is there a method to do this directly?

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


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

Perhaps I need to add a category to NSString?

Trygve

Related mailsAuthorDate
mlPrepending to fixed length Trygve Inda Jul 18, 21:43
mlRe: Prepending to fixed length Sherm Pendley Jul 18, 22:02
mlRe: Prepending to fixed length Trygve Inda Jul 18, 23:54
mlRe: Prepending to fixed length j o a r Jul 19, 00:00
mlRe: Prepending to fixed length stephen joseph but… Jul 19, 00:00
mlRe: Prepending to fixed length Trygve Inda Jul 19, 00:02
mlRe: Prepending to fixed length Robert Walker Jul 19, 00:10
mlRe: Prepending to fixed length Matt Neuburg Jul 19, 02:06
mlRe: Prepending to fixed length Trygve Inda Jul 19, 11:14