前端之家收集整理的这篇文章主要介绍了
GOlang中的string包用法,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
package main
import s "strings"
import "fmt"
var echo = fmt.Println
func main() {
echo("Contains: ",s.Contains("test","es"))
echo("Count: ",s.Count("test","t"))
echo("HasPrefix: ",s.HasPrefix("test","te"))
echo("HasSuffix: ",s.HasSuffix("test","st"))
echo("Index: ",s.Index("test","e"))
echo("Join: ",s.Join([]string{"a","b"},"-"))
echo("Repeat: ",s.Repeat("a",5))
echo("Replace: ",s.Replace("foo","o","0",-1))
echo("Replace: ",1))
echo("Split: ",s.Split("a-b-c-d-e","-"))
echo("ToLower: ",s.ToLower("TEST"))
echo("ToUpper: ",s.ToUpper("test"))
echo("Len: ",len("hello"))
echo("Char:","hello"[1])
}
原文链接:https://www.f2er.com/go/191283.html