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

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -