
上QQ阅读APP看书,第一时间看更新
Converting String to Long
Here's an example that shows parsing of string to Long:
fun main(args: Array<String>) {
val str="123"
print(str.toLong())
}
When you run the preceding code, you will see this output:
123
If you don’t want to deal with the exceptions, you can use .toLongOrNull(). This method parses the string as a Long and returns the result, or null if the string is not a valid representation of a number.