Does Cocoa’s printf-style formatting not work as expected when using %@ conversion specifier and field width?
My understanding of printf-like format strings is that you can prefix any conve开发者_如何学运维rsion specifier with a minimum field width. This does not seem to work for Cocoa’s %@
specifier.
Example:
NSLog(@"'%5@'", @"foo");
NSLog(@"'%5s'", [@"foo" UTF8String]);
Output:
… 'foo'
… ' foo'
Is this the intended behavior?
%@ is only for objective-c object. Thus, the field width will be invalid, if the object is not NSString.
I didn't know that %5@ is formatted to be the same as %@.
The %@ format specifier just gets replaced by the object's description. It doesn't do any truncation or padding.
精彩评论