首页科学探索golang的string字符串常用函数
47439

golang的string字符串常用函数

我要新鲜事2023-05-14 04:53:200

str1 := "itceshi"

result := strings.Contains(str1, "cesh")

fmt.Println(result)str := []string{"a", "b", "c", "d", "e", "f"}

join := strings.Join(str, "")

fmt.Println("join:", join)str := "[email protected]"

split := strings.Split(str, "@")

fmt.Println("split:", split)str := "qqhao123"

result3 := strings.Index(str, "hao")

fmt.Println("result:", result3)str := "Aceceshi"

result4 := strings.Repeat(str, 3)

fmt.Println("result:", result4)

func Replace(s, old, new string, n int) string

在s字符串中,把old字符串替换为new字符串,n表示替换的次数,小于0表示全部替换

str := "Azzhao"

strings.Replace(str, "z", "Z", 1)// 替换第一个

strings.Replace(str, "z", "Z", -1)// 全部替换

func Trim(s string, cutset string) string

t在s字符串的头部和尾部去除cutset指定的字符串

str := " [email protected] "

trim := strings.Trim(str, " ") // 去掉两头空格

fmt.Println("trim:", trim)str := " [email protected] "

fields := strings.Fields(str)

fmt.Println("fields:", fields)

热门推荐

1.golang的string、int、int64、float64互相转换

2.每日一招:搭建Jenkins,Gitlab自动化打包部署项目

3.每日一招:docker安装easyswoole

4.Linux安装MYSQL8.0

5.个人可以做哪些副业兼职赚钱?

0000
评论列表
共(0)条