首页 > kotlin2_4_10 > 语言指南
字符转换
2026-07-15 15:10:38 来源: 点击数:
字符转换
要把 Char 转成数字类型,需要显式转换:
-
Use
.codeto get the numeric Unicode value of a character:val letter = 'A'
println(letter.code) // 65
-
If a character represents a decimal digit, use
digitToInt():val digit = '7'
println(digit.digitToInt()) // 7
If the character may not be a valid digit, use
digitToIntOrNull().





