Go []byte数组/int转化为string

Go 语言中读取[]byte数组,获取到的数组元素类型会是int,eg:

package main

import (
	"fmt"
)

type IPAddr [4]byte

func main() {
    test := IPAddr{123,'T',3,1}
    temp := test[0]
    fmt.Printf("%T %v\n", temp, temp)
	temp = test[1]
    fmt.Printf("%T %v", temp, temp)
}

输出:
uint8 123
uint8 84

将int类型转换为string,eg:

package main

import (
	"fmt"
	"strconv"
)

type IPAddr [4]byte

func main() {
    test := IPAddr{123,12,3,1}

    result := ""
    for i:=0;i

将字符转化为string,eg:

package main

import (
	"fmt"
)

type IPAddr [4]byte

func main() {
    test := IPAddr{'T','e','s','t'}

    result := ""
    for i:=0;i

 

你可能感兴趣的:(Go)