Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
// Apply mask to credit card number
func applyMask(number: String) -> String {
let mask = "%2A%2A%2A+%2A%2A%2A%2A+%2A%2A%2A%2A+"
let startIndex = number.startIndex
let range = startIndex.advancedBy(1) ..< number.endIndex.advancedBy(-4)
let substring = number.substringWithRange(range)
let replacedWithMask = number.stringByReplacingOccurrencesOfString(substring, withString: mask)
return replacedWithMask
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.