Here is a simple way if I understood your question correctly:
NSString *fish = @"Chips"; NSString *length = [NSString stringWithFormat:@"%02d",[fish length]]; NSLog(@"Chips length is %@",length);
It produces:
2012-01-23 10:42:20.316 TestApp[222:707] Chips length is 05
02 means zero pad for length 2. You might want to check if your string is less than 99 characters long.
source share