Extract Float from String in Swift

Viewed 1117

I am able to extract numbers using below code:

let weightt = x.components(separatedBy: CharacterSet.decimalDigits.inverted).joined(separator: "")

For example, I'm getting "01" from string "0.1kg"

But how to extract "0.1" from string "0.1kg" ?

5 Answers
Related