0

I've got a number in a string like so: @"+316-55 840 659". I want this to transform to: @"+31655840659".

Right now, I'm using this:

[[number componentsSeparatedByCharactersInSet:
                           [[NSCharacterSet decimalDigitCharacterSet] invertedSet]]
                          componentsJoinedByString:@""];

Is there a way to modify [NSCharacterSet decimalDigitCharacterSet] so that it allows the + as well?

Cœur
  • 37,241
  • 25
  • 195
  • 267
bdv
  • 1,154
  • 2
  • 19
  • 42

1 Answers1

1

You can either do:

[NSCharacterSet characterSetWithCharactersInString:@"0123456789+"]

or:

[[[NSCharacterSet decimalCharacterSet] mutableCopy] addCharactersInString:@"+"]
Ricardo Sanchez-Saez
  • 9,466
  • 8
  • 53
  • 92