swift3 - Swift 3 Trimming characters -


anyone know how trim or eliminate characters string? have data uilabel "abcde1000001" , need numbers only. idea? trimming? concat? other solution?

i try looking other solution

 let cardtrim = string.trimmingcharacters(in: characterset(charactersin: "abcdef")) 

your code works perfectly, need call on string variable in store value want trim.

let stringtotrim = "abcde1000001" let cardtrim = stringtotrim.trimmingcharacters(in: characterset(charactersin: "abcdef")) //value: 1000001 

a more generic solution use characterset.decimaldigits.inverted keep digits string.

let cardtrim = stringtotrim.trimmingcharacters(in: characterset.decimaldigits.inverted) 

be aware trimmingcharacters removes characters in characterset beginning , end of string, if have string abc101a101 , want remove letters it, you'll have use different approach (for instance regular expressions).


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -