字符串函数在golang中的使用

字符串函数在golang中的使用,第1张

概述package main import ( "fmt" "strings" ) func main() { //判断父字符串是否包含子字符串,包含为真,否则为假 fmt.Println("-------------------------------") fmt.Println("contains Function:", strings.Contains("Austrilia", "lia")) package main import ( "fmt" "strings" ) func main() { //判断父字符串是否包含子字符串,包含为真,否则为假 fmt.Println("-------------------------------") fmt.Println("contains Function:",strings.Contains("Austrilia","lia")) fmt.Println("contains Function:","mia")) //子字符串在父字符串中出现的次数 fmt.Println("-------------------------------") fmt.Println("Count Function: ",strings.Count("Australia","lia")) fmt.Println("Count Function: ","A")) fmt.Println("Count Function: ","Bu")) //判断子字符串是否为父字符串的前缀 fmt.Println("-------------------------------") fmt.Println("HasPrefix Function: ",strings.HasPrefix("Australia","Bu")) fmt.Println("HasPrefix Function: ","Aus")) ////判断子字符串是否为父字符串的后缀 fmt.Println("-------------------------------") fmt.Println("HasSuffix Function: ",strings.HasSuffix("Australia","lia")) fmt.Println("HasSuffix Function: ","tia")) //子字符串首次出现在父子符串的索引下标 fmt.Println("-------------------------------") fmt.Println("Index Function:",strings.Index("Australia","lia")) fmt.Println("Index Function: ","a")) fmt.Println("Index Function: ","A")) //连接函数,指定分隔符将字符串连接起来 fmt.Println("-------------------------------") fmt.Println("Join Functions:",strings.Join([]string{"Austrilia","Japen","Germany"},"-")) fmt.Println("Join Function: ",strings.Join([]string{"Australia","Japan"," ")) //重复函数,指定字符串重复出现的次数 fmt.Println("-------------------------------") fmt.Println("Repeat Function:",strings.Repeat("Australia",3)) //替换字符串函数, fmt.Println("-------------------------------") fmt.Println("Replace Function: ",strings.Replace("Australia ","a","b",1)) fmt.Println("Replace Function: ",2)) fmt.Println("Replace Function: ",strings.Replace("Aaustralia ",3)) fmt.Println("Replace Function: ","A","B","lia","pia",1)) //分割函数,指定分隔符分隔字符串 fmt.Println("-------------------------------") fmt.Println("Split Function:",strings.Split("Australia-Japan-Germany","-")) //把字符转小写 fmt.Println("-------------------------------") fmt.Println("Tolower Function: ",strings.Tolower("Australia")) //把字符串转大写 fmt.Println("-------------------------------") fmt.Println("toupper Function: ",strings.toupper("Australia")) } 总结

以上是内存溢出为你收集整理的字符串函数在golang中的使用全部内容,希望文章能够帮你解决字符串函数在golang中的使用所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1268387.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-08
下一篇 2022-06-08

发表评论

登录后才能评论

评论列表(0条)

保存