In Go, you want to do a conversion.
Conversions
Conversions are expressions of the form T(x)
where T
is a type and
x
is an expression that can be converted to type T
.
Conversion = Type "(" Expression ")" .
A non-constant value x
can be converted to type T
in any of these
cases:
x
is assignable to T
.
x
's type and T
have identical underlying types.
x
's type and T
are unnamed pointer types and their pointer base types have identical underlying types.
x
's type and T
are both integer or floating point types.
x
's type and T
are both complex types.
x
is an integer or has type []byte
or []rune
and T
is a string type.
x
is a string and T
is []byte
or []rune
.
You want to convert x
, of type int
, int32
, or int64
, to T
of type rune
, an alias for type int32
. x
's type and T
are both integer types.
Therefore, T(x)
is allowed and is written rune(x)
, for your example, c = rune(i)
.
int32(i)
orrune(i)
to set an int to a rune. See https://mcmap.net/q/55267/-idiomatic-type-conversion-in-go.int(r)
to set a rune to an int. See https://mcmap.net/q/56310/-golang-how-does-the-rune-function-work. – Diuresis