The article directories

String is converted to []byte. 2. Byte is converted to String


Go byte arrays are converted to and from strings

String cannot be converted directly to an array of bytes. String can be converted to a slice of byte


1. String is converted to []byte

var str string = "test"
var data []byte = []byte(str)
Copy the code

2. Byte is converted to string

var data [10]byte 
byte[0] = 'T'
byte[1] = 'E'
var str string = string(data[:])
Copy the code