Add spaces to infront of a string?
ios, ios4, ios5, objective-c
Solution
You might like `NSString`'s `stringByPaddingToLength:withString:startingAtIndex`
NSString *result = [NSString stringWithFormat:@"%@%@",
[@" " stringByPaddingToLength:spaces_needed withString:@" " startingAtIndex:0]
[dicBusinessDetails objectForKey:@"ResturantName"]];
Problem
I want to add spaces (" ") infront of a string (like white spaces). this is the length of the spaces ``` int spaces_needed=((36-[[dicBusinessDetails objectForKey:@"ResturantName"] length]))/2; ``` What I want is to create a string like this ``` NSString stringWithFormat:@" %@",[dicBusinessDetails objectForKey:@"ResturantName"]; ``` But the spaces should NOT be fixed as above, but variable length of int spaces_needed. Actual reason for doing this is to center align a string in a receipt