Go byte 배열

1 개요[ | ]

Go []bytes
Go byte 배열
package main

import "fmt"

func main() {
    a := []byte("Hello")
    fmt.Println(a) // [72 101 108 108 111]
}
package main

import (
    "fmt"
    "reflect"
)

func main() {
    a := []byte("Hello")
    fmt.Println(reflect.TypeOf(a)) // []uint8
    fmt.Println(a) // [72 101 108 108 111]
}

2 기타: 문자열, 구조체[ | ]

package main

import (
	"encoding/json"
	"fmt"
)

type Hello struct {
	Foo string
}

func main() {
	bytes1 := []byte(`{"Foo":"Bar"}`)             // string → []byte
	bytes2, _ := json.Marshal(&Hello{Foo: "Bar"}) // marshal struct

	fmt.Printf("%s\n", bytes1) // {"Foo":"Bar"}
	fmt.Printf("%s\n", bytes2) // {"Foo":"Bar"}
	fmt.Printf("%v\n", bytes1) // [123 34 70 111 111 34 58 34 66 97 114 34 125]
	fmt.Printf("%v\n", bytes2) // [123 34 70 111 111 34 58 34 66 97 114 34 125]
}

3 같이 보기[ | ]

4 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}