package main import "fmt" func main() { slice1 := []byte{1, 2, 3, 4, 5} slice2 := []byte{5, 4, 3} copy(slice2, slice1) // 只会复制slice1的前3个元素到slice2中 fmt.Printf("%x\n",slice1) fmt.Printf("%x\n",slice2) copy(slice1, slice2) // 只会复制slice2的3个元素到slice1的前3个位置 fmt.Printf("%x\n",slice1) fmt.Printf("%x\n",slice2) var md5code [16]byte arybyte := md5code[0:16] aryb2 := []byte{0,1,2,3,4,5,6,7,8,9,0xA,0xB,0xC,0xD,0xE,0xF} copy(arybyte,aryb2) fmt.Printf("%x",md5code) } /* D:\gotest>go build copytest.go D:\gotest>copytest.exe 0102030405 010203 0102030405 010203 000102030405060708090a0b0c0d0e0f */
有疑问加站长微信联系(非本文作者)