package main
import (
"fmt"
"strings"
)
func main(){
s1 := "helloworld"
//是否包含指定的内容-->bool
fmt.Println(strings.Contains(s1,"l"))
//是否包含任意字符
fmt.Println(strings.ContainsAny(s1,"abcd"))
//统计l在s1出现的次数
fmt.Println(strings.Count(s1,"l"))
s2 := "20190525课堂笔记.txt"
//以xxx开头
if strings.HasPrefix(s2,"201905"){
fmt.Println("19年5月的文件。。")
}
//以xxx结尾
if strings.HasSuffix(s2,".txt"){
fmt.Println("文本文档")
}
//查找llo在s1中的位置,如果不存在返回-1
fmt.Println(strings.Index(s1,"llo"))
fmt.Println(strings.LastIndex(s1,"h"))
//字符串的拼接
ss1 := []string{"abc","world","hello","rudy"}
s3 := strings.Join(ss1,"*")
fmt.Println(s3)
//切割,
s4 := "123,456,789,abc"
ss2 := strings.Split(s4,",")
fmt.Printf("ss2的类型是%T,数值是%s\n",ss2,ss2)
}
网友评论