I padded a Swift String up to X amount of characters. Which is the most efficient way to achieve this in Swift 4.0?
Option 1
extension String {
mutating func right_padding(padding: Int, padding_char: Character) {
let idx = self.endIndex
for _ in (1...padding) {
self.insert(padding_char, at: idx)
}
}
}
Option 2 SO article: Padding a swift String for printing
let test = "ghost" + "\(String(repeatElement("!", count: 40)))"
Option 3
???
Option 2 seems the simplest & most efficient, but I may be missing a better way...