Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
enum StringPaddingStyle {case Left, Right}
func padStringToLength(
sourceString: String,
destinationCount: Int,
paddingStyle: StringPaddingStyle = .Left,
paddingCharacter: Character = " "
) -> String {
let padCount = destinationCount - sourceString.characters.count
let padString = String(count: padCount, repeatedValue: paddingCharacter)
return
paddingStyle == .Left
? padString + sourceString
: sourceString + padString
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment