How to remove numbers from a string in Swift

I have a string like "75003 Paris, France" or "Syracuse, NY 13205, USA" .

I want to use the same code to remove all these numbers from these lines.

How can i achieve this?

+6
source share
1 answer

You can do it with NSCharacterSet

 var str = "75003 Paris, France" var stringWithoutDigit = (str.componentsSeparatedByCharactersInSet(NSCharacterSet.decimalDigitCharacterSet()) as NSArray).componentsJoinedByString("") println(stringWithoutDigit) 

Output:

 Paris, France 

Taken from: fooobar.com/questions/40460 / ...

+18
source

All Articles