How to convert uint8 to string

You can do it even simpler by using casting, this worked for me:

var c uint8
c = 't'
fmt.Printf(string(c))

There is a difference between converting it or casting it, consider:

var s uint8 = 10
fmt.Print(string(s))
fmt.Print(strconv.Itoa(int(s)))

The string cast prints '\n' (newline), the string conversion prints "10". The difference becomes clear once you regard the []byte conversion of both variants:

[]byte(string(s)) == [10] // the single character represented by 10
[]byte(strconv.Itoa(int(s))) == [49, 48] // character encoding for '1' and '0'
see this code in play.golang.org

Simply convert it :

    fmt.Println(strconv.Itoa(int(str[1])))

Tags:

Go