Created
November 24, 2015 15:57
-
-
Save erica/efbe3e92669077349d5a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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