golang之string标准库(二)
来源:互联网 发布:qq偷菜软件下载 编辑:程序博客网 时间:2024/05/23 16:42
1:Field(s string)[]string:以1个或多个空格字符串,分割字符串,返回所有子串,如果父串是空,则返回空串
str = "helloworld hellogolang helloprograming hellotest hellostring hello" newstr := strings.Fields(str) fmt.Println("Fields :", newstr)
2:FieldFunc(s string ,f func(rune) bool)[]string:按照函数f分割字符串,返回所有子串
func split(s rune) bool { if s == 'n' { return true } return false } str = "helloworld hellogolang helloprograming hellotest hellostring hello" newstr = strings.FieldsFunc(str, split) fmt.Println("FiledFunc :", newstr)
3:Join(a []string,sep string)string:这个函数是将一个[]string的切片通过分隔符,分割成一个字符串
srcstr := []string{"helloworld", "helloprograming", "hellostrings"} sep = "hello" dststr := strings.Join(srcstr, sep) fmt.Println("Join :", dststr)
4:HasPrefix(s,prefix string)bool:判断字符串s是否包含prefix前缀
prefix := "hello" str = "helloworld hellogolang helloprograming hellotest hellostring hello" ishave := strings.HasPrefix(str, prefix) if ishave { fmt.Println("HasPrefix exist") } else { fmt.Println("HasPrefix is not exist") }
5:HasSuffix(s,suffix string)bool:判断字符串s是否包含suffix后缀
suffix := "hello" str = "helloworld hellogolang helloprograming hellotest hellostring hello" ishave = strings.HasSuffix(str, suffix) if ishave { fmt.Println("HasSuffix exist") } else { fmt.Println("HasSuffix not exist") }
6:Map(mapping func(rune) rune,s string)string:字符串的每一个字符通过mapping函数的处理,最后返回处理好的字符串,如果处理不正确,那么就抛弃该字符
str = "helloworld hellogolang helloprograming hellotest hellostring hello" func mmap(s rune) rune { if s == 'o' { return 'n' } return 'q'} mapString := strings.Map(mmap, str) fmt.Println("map ", mapString)
7:Repeat(s string,count int)string:将s复制count份,返回新的字符串
dststr = strings.Repeat("hello", 3) fmt.Println("Repeat ", dststr)
8:ToUpper(s string)string:将字符串中的所有字符转成大写
upperstr := strings.ToUpper("hellO") fmt.Println("ToUpper :", upperstr)
9:ToLower(s string)string:将字符串中所有的字符转成小写
lowerstr := strings.ToLower("HELLO") fmt.Println("ToLower :", lowerstr)
10:ToTitle(s string)string:将字符串的所有字符转成标题体
titlestr := strings.ToTitle("hello world hello golang") fmt.Println("ToTitle :", titlestr)
11:Title(s string)string:将字符串转成首字符大写
fmt.Println("Title:", strings.Title("hello world hello golang"))
11:ToUpperSpecial(c unicode.SpecialCase, s string)string:该函数把s字符串里面的每个单词转化为大写,但是调用的是unicode.SpecialCase的ToUpper方法
var SC unicode.SpecialCase fmt.Println("ToUpperSpecial:", strings.ToUpperSpecial(SC, "Gopher"))
12:ToLowerSpecial(c unicode.SpecialCase, s string) string:该函数把s字符串里面的每个单词转化为小写,但是调用的是unicode.SpecialCase的ToLower方法
var SC unicode.SpecialCase fmt.Println("ToLowerSpecial:", strings.ToLowerSpecial(SC, "GOLANG"))
13:ToTitleSpecial(c unicode.SpecialCase, s string) string:该函数把s字符串里面的每个单词转化为标题体,但是调用的是unicode.SpecialCase的ToTitle方法
var SC unicode.SpecialCase fmt.Println("ToTitleSpecial:", strings.ToTitleSpecial(SC, "hello world"))
- golang之string标准库(二)
- golang之string标准库(一)
- golang之string标准库(三)
- 《c++标准程序库》读后感之string 二
- golang标准库 io
- Golang标准库文档
- C++ 标准库 string类型(二)
- golang讲解(go语言)标准库分析之strings
- 标准C++中的string类的简单总结之二
- golang标准库的学习
- Golang 部分标准库说明
- golang标准库 time包
- golang标准库 time包
- 初探c++标准库之string
- c++之标准库类型string
- 《c++标准程序库》读后感之 string 二 :string class的内部类型定义和静态值
- C++学习笔记(二) —— 标准库String类
- golang-redis之string类型简单操作
- Centos生成火车(提升Linux兴趣)
- Unable to parse template "Annotation" Error message: This template did not produce a Java class or a
- 新手村 简单字符串 ISBN号码
- 图的邻接矩阵的实现
- 1034. 有理数四则运算(20) PAT乙级真题
- golang之string标准库(二)
- Fresco图片加载框架
- openCV学习之路【3】--一篇文章读懂OpenCV3
- HDOJ 1018 数学(N的阶乘)
- Ubuntu下安装并配置VS Code编译C++
- 2017秋招之面试整理(3)
- GreenDao,注解,RecyclerView,EventBus,Retrofit展示列表
- Kotlin基本数据类型
- java权限拦截器