Is there a way to set an int to 001
Posted
by
H.aLFaRSi
on Stack Overflow
See other posts from Stack Overflow
or by H.aLFaRSi
Published on 2012-06-20T02:53:12Z
Indexed on
2012/06/20
3:16 UTC
Read the original article
Hit count: 210
i need to set an integer to start from 001 instead of only 1
int iNumber = 001;
NSLog(@"%d",iNumber); // this is logging 1 instead of 001
is there a possible way to make it 001 ?
[UPDATED]
i need this because i`m creating an NSMutableArray from NSUserDefaults, after that I'm sorting the array using NSSortDescriptor. the problem is because i can't set the int to start from 001 the array i sorted like this 0, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9.
More Code explained
NSString *name = @"Name";
NSUserDefaults *MainArray = [NSUserDefaults standardUserDefaults];
NSString *Temp = [NSString stringWithFormat:@"%@%d", name,MainNumber];
[MainArray setObject:@"test" forKey:Temp];
[MainArray synchronize];
NSLog(@"%@",Temp);
MainNumber++;
the above code will save it like this : Name1,Name2,Name3....
i need it to be Name001, Name002, Name003 .......
thank you in advance :)
© Stack Overflow or respective owner