How do I convert a String to a Long in Swift?
In Java I would do Long.parseLong("str", Character.MAX_RADIX)
.
As noted here, you can use the standard library function strtoul():
let base36 = "1ARZ"
let number = strtoul(base36, nil, 36)
println(number) // Output: 60623
The third parameter is the radix. See the man page for how the function handles whitespace and other details.
We now have these conversion functions built-in in Swift Standard Library:
Encode using base 2 through 36: https://developer.apple.com/documentation/swift/string/2997127-init Decode using base 2 through 36: https://developer.apple.com/documentation/swift/int/2924481-init
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With