2

I need to remove all the numbers from a string, but the code that I have is in swift 2.3

let string = (string.componentsSeparatedByCharactersInSet(NSCharacterSet.decimalDigitCharacterSet()) as NSArray).componentsJoinedByString("")

How can I do the same in swift 3? thanks!

Bilal
  • 18,478
  • 8
  • 57
  • 72
100tomer
  • 137
  • 1
  • 10
  • Google: https://www.google.nl/search?client=safari&rls=en&q=remove+numbers+from+string+swift&ie=UTF-8&oe=UTF-8&gfe_rd=cr&ei=FVRqWb_-OaPH8AfGpbOgAw#q=remove+numbers+from+string+swift+3 all answers are there – J. Doe Jul 15 '17 at 17:43
  • I'm pretty sure the Xcode compiler will help you with this, if not it's a _very_ simple change with which Google will definitely be you friend! – Kane Cheshire Jul 15 '17 at 17:44
  • I try to search on Google, I come down empty. – 100tomer Jul 15 '17 at 17:48

1 Answers1

24

Try this code

let string = string.components(separatedBy: CharacterSet.decimalDigits).joined()
Fangming
  • 24,551
  • 6
  • 100
  • 90