Tag: padding

Padding a swift String for printing

问题内容: I’m trying to print a list of Strings all padded to the same width. In C, I would use something like printf("%40s", cstr), where cstr is a C string. In Swift, the best I could come up is this: line += String(format: "%40s",string.cStringUsingEncoding(<someEncoding>)) Is there a better way ? 问题评论: 答案: 答案1: NSString has