package main
import (
"fmt"
"strconv"
)
func main() {
v := "55"
if s, err := strconv.Atoi(v); err == nil {
fmt.Println(string(v)) // 55
fmt.Println(s) // 55
fmt.Println(string(s)) // 7
}
}
s
is an integer with the value 55, which is the ASCII (and UTF-8) encoding of the character "7"
. That's what's printed from the last statement.
When you call s, err := strconv.Atoi("55")
you turn s
into an integer. When you do string(s)
afterwards, you're asking for a string that contains the character represented by that integer.
That character happens to be '7'
. Try v := "65"
and you'll get 'A'
, etc.