[Solved] How to parse a String like “14px” to get Int value 14 in Swift [duplicate]


If string always come with just px at last you can subscript it and ignore the last 2 characters.

let str = "14px"  
var numStr = str.substring(to: str.index(name.endIndex, offsetBy: -2))
print(numStr) // "14"
//Now you can convert "14" to Int
print(Int(numStr))

Or

print(Int(String(str.characters.dropLast(2))))

solved How to parse a String like “14px” to get Int value 14 in Swift [duplicate]