write unicode character


To write a Unicode-character in code preface the hexadecimal value with \u or \U.
Because they need at least 2 bytes we have to use the int16 or int type. If 4 bytes are needed for the character \U is used; \u is always followed by exactly 4 hexadecimal digits and \U by 8 .

package main
import "fmt"
func main() {
    ch := '\u0041'
    ch2 := '\u03B2'
    ch3 := '\U00101234'
    fmt.Printf("%d = %d - %d\n", ch, ch2, ch3)
}
//65 = 946 - 1053236

source--The Way To Go

No comments:

Post a Comment