Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save onmyway133/f528306c3c530920e84b to your computer and use it in GitHub Desktop.

Select an option

Save onmyway133/f528306c3c530920e84b to your computer and use it in GitHub Desktop.
enum StringPaddingStyle {case Left, Right}
func padStringToLength(
sourceString: String,
destinationCount: Int,
paddingStyle: StringPaddingStyle = .Left,
paddingCharacter: Character = " "
) -> String {
let padCount = destinationCount - sourceString.characters.count,
padString = String(count: padCount, repeatedValue: paddingCharacter)
return paddingStyle == .Left ? padString + sourceString
: sourceString + padString
}
func elongatedToShowRationaleForShortcuts(
sourceString: String,
destinationCount: Int,
paddingStyle: StringPaddingStyle = .Left,
paddingCharacter: Character = " "
) -> String {
let standsAlone = ""
let
standsAlone1 = "",
standsAlone2 = "",
standsAlone3 = ""
let isUsedAgainInThisList = "",
reliesOnIsUsedInThisList = isUsedAgainInThisList,
andThisAlsoRelies = isUsedAgainInThisList
let padCount = destinationCount - sourceString.characters.count,
padString = String(count: padCount, repeatedValue: paddingCharacter)
return {
if paddingStyle == .Left {return padString + sourceString}
else {return sourceString + padString}
}()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment