uint8 the set of all unsigned 8-bit integers (0 to 255) int32 the set of all signed 32-bit integers (-2147483648 to 2147483647) byte alias for uint8 rune alias for int32
能夠經過下面程序驗證:golang
package main import "fmt" func byteSlice(b []byte) []byte { return b } func runeSlice(r []rune) []rune { return r } func main() { b := []byte{0, 1} u8 := []uint8{2, 3} fmt.Printf("%T %T \n", b, u8) fmt.Println(byteSlice(b)) fmt.Println(byteSlice(u8)) r := []rune{4, 5} i32 := []int32{6, 7} fmt.Printf("%T %T \n", r, i32) fmt.Println(runeSlice(r)) fmt.Println(runeSlice(i32)) }
執行結果以下:c#
[]uint8 []uint8 [0 1] [2 3] []int32 []int32 [4 5] [6 7]
package main import ( "fmt" ) func main() { var indexRuneTests = []struct { s string rune rune out int }{ //string用反引號能換行, 但不支持轉義, rune是一個uint32,即一個unicode字符 {`as\n df`, 'A', 2}, //用雙引號不能換行, 但支持轉義如"\n\t..", rune是一個uint32,即一個unicode字符 {"some_text\n=some_value", '=', 9}, {"☺a", '☺', 3}, {"a☻☺b", '☺', 4}, } fmt.Println("Hello, playground",indexRuneTests) }
Hello, playground [{as\n df 65 2} {some_text =some_value 61 9} {☺a 9786 3} {a☻☺b 9786 4}]
參考資料:
Difference between []uint8 && []byte (Golang Slices)。ui