Hacker symbol

September 8, 2019 ~ 1 min read

Convert rune to int


An alternative to strconv.Atoi(string(n)) is int(n-'0') which should be safe after validating that n is a number with unicode.IsNumber()

if !unicode.IsNumber(runeValue) { return false } //this
runeNumber, _ := strconv.Atoi(string(runeValue)) // same as this runeNumber = int(runeValue - '0')

Sebastian BolaƱos

Hi, I'm Sebastian. I'm a software developer from Costa Rica. You can follow me on Twitter. I enjoy working on distributed systems.