Junior — Middle
Kuidas saab baitide massiivi muuta tekstijadeks?
sobes.tech AI
Vastus AI-lt
In Go, to convert a byte array ([]byte) to a string, a simple type conversion is used:
bytes := []byte{72, 101, 108, 108, 111}
str := string(bytes)
fmt.Println(str) // Will output: Hello
This conversion copies the bytes into the string and interprets them as UTF-8 characters. If the bytes do not form a valid UTF-8 sequence, the result may be incorrect.