Go 语言标准库之 strings包
来源:互联网 发布:wps数据有效性设置取消 编辑:程序博客网 时间:2024/05/22 13:06
(1)func Contains(s, substr string) bool
这个函数是查找某个字符是否在这个字符串中存在,存在返回true
[php]
import (
"fmt"
"strings"
)
func main() {
fmt.Println(strings.Contains("widuu", "wi")) //true
fmt.Println(strings.Contains("wi", "widuu")) //false
}
[/php]
(2)func ContainsAny(s, chars string) bool
这个是查询字符串中是否包含多个字符
[php]
import (
"fmt"
"strings"
)
func main() {
fmt.Println(strings.ContainsAny("widuu", "w&d")) //true
}
[/php]
(3)func ContainsRune(s string, r rune) bool
,这里边当然是字符串中是否包含rune类型,其中rune类型是utf8.RUneCountString可以完整表示全部Unicode字符的类型
[php]
import (
"fmt"
"strings"
)
func main() {
fmt.Println(strings.ContainsRune("widuu", rune('w'))) //true
fmt.Println(strings.ContainsRune("widuu", 20)) //fasle
}
[/php]
(4)func Count(s, sep string) int
这个的作用就是输出,在一段字符串中有多少匹配到的字符
[php]
import (
"fmt"
"strings"
)
func main() {
fmt.Println(strings.Count("widuu", "uu")) //1
fmt.Println(strings.Count("widuu", "u")) //2
}
[/php]
(5)func EqualFold(s, t string) bool
这个是判断s,t两个字符串在完全小写的情况下是否相等uff8编码
[php]
import (
"fmt"
"strings"
)
func main() {
fmt.Println(strings.EqualFold("WIDUU", "widuu")) //true
}
[/php]
(6)func Fields(s string) []string
,这个函数的作用是按照1:n个空格来分割字符串最后返回的是[]string的切片
[php]
import (
"fmt"
"strings"
)
func main() {
fmt.Println(strings.Fields("hello widuu golang")) //out [hello widuu golang]
}
[/php]
(7)func FieldsFunc(s string, f func(rune) bool) []string
一看就了解了,这就是根据自定义函数分割了
[php]
import (
"fmt"
"strings"
)
func main() {
fmt.Println(strings.FieldsFunc("widuunhellonword", split)) // [widuu hello word]根据n字符分割
}
func split(s rune) bool {
if s == 'n' {
return true
}
return false
}
[/php]
(8)func HasPrefix(s, prefix string) bool
,判断是否以什么字符串开头的
[php]
import (
"fmt"
"strings"
)
func main() {
fmt.Println(strings.HasPrefix("widuu_web", "widuu")) //true
}
[/php]
(9)func HasSuffix(s, suffix string) bool
,判断是否有什么后缀,返回bool值
[php]
import (
"fmt"
"strings"
)
func main() {
fmt.Println(strings.HasSuffix("nihaowiduu", "widuu")) //true
}
[/php]
- Go 语言标准库之 strings包
- golang讲解(go语言)标准库分析之strings
- Go语言学习之strings包(the way to go)
- go语言 看代码,学strings包
- Go 标准库介绍一: strings
- 九、Go语言库之strconv包--GO语言笔记
- 八、Go语言包之strings--go语言学习笔记
- Go语言——strings包常用函数整理
- GO语言标准库概览
- 标准库— 操作源码之收集go包信息:go/build
- Go常用包系列---strings包
- go语言学习之gzip包解读
- Go语言学习之ioutil包(The way to go)
- Go语言学习之net包(The way to go)
- Go语言学习之bufio包(The way to go)
- Go语言学习之errors包(The way to go)
- Go语言学习之log包(The way to go)
- Go语言学习之runtime包(The way to go)
- redis删除指定开头的键值数据(命令行)
- 帝国cms制作手机wap站完美教程
- 注册码系统防破解教程,如何防破解?
- 入门深度学习mxnet框架——运行mnist手写数字例子
- jquery 遍历
- Go 语言标准库之 strings包
- Android总结篇系列:Activity启动模式(lauchMode)
- menu 菜单层级关系MAP组装
- vimrc文件的配置
- LeetCode 12. Integer to Roman
- js闭包
- 机器人驱动介绍(2)
- 加载 Logo 动画 试玩
- mysql出现Connection.close() has already been called. Invalid operation in this state.