Demo
package main
import (
"fmt"
"strings"
"gitee.com/liumou_site/glbm"
"gitee.com/liumou_site/logger"
)
func main() {
fmt.Println("切片")
logger.Info("坐公交也用券")
s := strings.Split("a b c", " ")
logger.Debug("切片内容: ", s)
logger.Debug("切片数量: ", len(s))
logger.Debug("第一个元素: ", s[0])
s = append(s, "d")
logger.Info("添加之后: ", s)
s = s[1:]
logger.Debug("删除第一个元素: ", s)
del_ := 1
s = append(s[:del_], s[del_+1:]...)
logger.Debug("删除第二个元素: ", s)
s = append(s, "a", "c", "刘某")
logger.Debug("添加多个元素: ", s)
ss := glbm.SliceToString(s, "")
logger.Info("字符串内容: ", ss)
var si []int
si = append(si, 1)
logger.Info("当前切片内容: ", si)
for index, value := range s {
logger.Warn(index, value)
}
end := append([]string{"头部"}, s...)
logger.Debug("头部添加元素之后: ", end)
logger.Error("切片只能储存同类型元素")
}
效果
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/117097c9a6322228b3c602b8c0e9dbb2.png)