2021
05-25
05-25
Go语言切片前或中间插入项与内置copy()函数详解
内置append()函数能够在切片末尾位置添加新的项,假设要在切片的前面或者中间某位置插入特定项,可以这样实现看下代码:packagemainimport"fmt"funcmain(){s:=[]string{"M","N","O","P","Q","R"}x:=InsertStringSliceCopy(s,[]string{"a","b","c"},0)y:=InsertStringSliceCopy(s,[]string{"a","b","c"},3)fmt.Printf("%v\n%v\n",x,y)}funcInsertStringSliceCopy(slice,insertion[]string,indexint)[]...
继续阅读 >