Go 字符串操作 — strings 包
strings 包常用函数:查找、替换、分割、拼接 · 难度:入门 · +15XP
strings 包
Go 的 strings 包提供字符串处理函数,全在 strings 下。
常用函数
strings.Contains("hello world", "world") // true
strings.HasPrefix("file.go", "file") // true
strings.HasSuffix("app.go", ".go") // true
strings.Index("hello", "ll") // 2
strings.Replace("a,b,c", ",", "|", -1) // "a|b|c"
strings.Split("a,b,c", ",") // [a b c]
strings.Join([]string{"a","b"}, "-") // "a-b"
strings.ToUpper("hello") // "HELLO"
strings.Trim(" hi ", " ") // "hi"