string - How to deal with separator format in Swift 3 -


having great deal of trouble finding way (formating) remove comma , if no comma found leave is.

what hoping achieve taking result of distance , displaying in label format is:

4589.163

instead of

4,589.163

if no comma separator found leave

479.996

my code:

if tempdistancestring.contains(",") {        let newstring = tempdistancestring.replacingoccurrences(of: ",", with: "") } 

i'm looking formatter if supportable requirement.

any appreciated.

swift 3.1

just replace occurrences of comma blank string.

let astring = "4,589.163" let newstring = astring.replacingoccurrences(of: ",", with: "") 

Comments

Popular posts from this blog

python - Best design pattern for collection of objects -

go - serving up pdfs using golang -

python - django admin: changing the way a field (w/ relationship to another model) is submitted on a form so that it can be submitted multiple times -