How to pad NSString with spaces?
Here is an example of how you can do it:
int main (int argc, const char * argv[]) {
NSString *str = @"Hello";
int add = 8-[str length];
if (add > 0) {
NSString *pad = [[NSString string] stringByPaddingToLength:add withString:@" " startingAtIndex:0];
str = [pad stringByAppendingString:str];
}
NSLog(@"'%@'", str);
return 0;
}
I just do something like this:
NSLog(@"%*c%@", 14 - theString.length, ' ', theString);
Moreover, 14
is the width that you want.