go笔记
二维数组的copy
package main
import "fmt"
func main() {
data := [][]string{
[]string{"id", "title"},
[]string{"1", "title1"},
[]string{"2", "title2"},
[]string{"3", "title3"},
[]string{"4", "title4"},
}
dst := make([][]string, len(data)) // copy的变量, 里面类型根据自己需要来设定,
copy(dst, data)
// 修改下标为3的元素
dst[3] = []string{"AAA", "BBB"}
fmt.Println(data) //[[id title] [1 title1] [2 title2] [3 title3] [4 title4]]
fmt.Println(dst) //[[id title] [1 title1] [2 title2] [AAA BBB] [4 title4]]
// 删除下标为2的元素
dst = append(dst[:2], dst[3:]...)
fmt.Println(data) //[[id title] [1 title1] [2 title2] [3 title3] [4 title4]]
fmt.Println(dst) //[[id title] [1 title1] [AAA BBB] [4 title4]]
}