1

I have an array of phonenumbers from my phone's contacts list that are are in different formats ranging from +1 (123) 123-1234, 1231231234, +11231231234, and 123-123-1234. I want them to all be in the format of 1231231234, but I don't much about string formatting. Can anyone point me in the right direction?

Trip Phillips
  • 430
  • 1
  • 5
  • 18

1 Answers1

1

Try something like this:

let digits = NSCharacterSet.decimalDigitCharacterSet()
var phoneNumberDigits = ""

for character in phoneNumber.unicodeScalars {
    if digits.longCharacterIsMember(character.value) {
        phoneNumberDigits += String(character)
    }
}
yesthisisjoe
  • 1,987
  • 2
  • 16
  • 32