切割文件名

切割文件名

✍️ 在编写日志库中用到的,和python里的字符串split()用法类似,但py里写法更直接,strname.split('.')就可以,切割出文件名后,再加-err拼接成err日志名, 以后遇到类似的需求,要想到这个小demo!

func main() {
	filestr := "file.log"
	fileSp := strings.Split(filestr, ".")[0]
	fmt.Printf(fileSp)
}

out

file

如果strings.Split(filestr, ".")[0],索引换成1,输出的就是log

posted @ 2022-08-31 21:53  sunnybowen  阅读(17)  评论(0编辑  收藏  举报