Post

Go rune type

Understanding Go's rune type, which is an alias for int32 used to represent Unicode code points.

This snippet demonstrates Go’s rune type, which is an alias for int32. A rune represents a Unicode code point. The example also shows how to convert a string to a byte slice using []byte(). Note that strings in Go must use double quotes, while single quotes are reserved for rune literals.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
func arrays()  {
	// !!! if declating string -> use double quotes ""
	s := "this is a string"
	b := []byte(s)
	fmt.Printf("%v, %T\n", b, b)

	// !!! rune <- this is a type and it is represented as int32
	// "rune" is a type alias for "int32"
	r := 'a'
	var x rune = 'a'

	fmt.Printf("%v, %T", r, r)
	fmt.Printf("%v, %T", x, x)
}
This post is licensed under CC BY 4.0 by the author.