A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-27.go
1packagemain
2
3import"fmt"
4
5funcmain(){
6dst:=make([]byte,3)
7n:=copy(dst,"hello")
8fmt.Println(n,string(dst))
9}
Slices
Answer & explanation
Console output
3 hel
Why
Go provides a special form of copy that copies the bytes of a string into a []byte destination. It still copies min(len(dst), len(src)) bytes, so only the first 3 bytes "hel" are written and n is 3. This is the idiomatic way to convert part of a string into bytes.