只列举了部分函数方法的使用:

太多了。。。。。。。

package main

import (
"fmt"
"strings"
) func main() {
Count计算 sep在s中的非重叠个数
func Count(s, substr string) int {
s := "Hello,超哥"
统计 l 出现的次数
n := strings.Count(s, "l")
fmt.Println(n) //
如果substr 为空,返回s中字符个数+
n=strings.Count(s,"")
fmt.Println(n) Contains判断 字符串 s中 是否包含 子串 substr
func Contains(s, substr string) bool {
substr什么都不写,返回true
存在返回true,否则false
s := "Hello,超哥!!"
b := strings.Contains(s, "!")
fmt.Println(b) //true
b = strings.Contains(s, "@") //false
fmt.Println(b)
b=strings.Contains(s,"")
fmt.Println(b) ContainsAny 判断字符串 s 中是否 包含 chars 中的任意一个字符
如果char为空,返回false
func ContainsAny(s, chars string) bool {
s := "Hello,超哥"
b := strings.ContainsAny(s,"abc")
fmt.Println(b)//false
b=strings.ContainsAny(s,"def")//true
fmt.Println(b)
b=strings.ContainsAny(s,"")//false
fmt.Println(b) ContainsRune判断字符串s中是否包含字符r
rune不能为空,存在true,否则false
func ContainsRune(s string, r rune) bool {
s := "Hello,超哥!"
b := strings.ContainsRune(s, '\n')
fmt.Println(b) //false
b = strings.ContainsRune(s, '超')
fmt.Println(b) //true
b = strings.ContainsRune(s, 'o')
fmt.Println(b)//true IndexAny 返回字符串 chars中的任何一个字符 在字符串s中 第一次出现的位置(索引)
找不到返回- ,chars为空也返回-
func strings.IndexAny()
s := "Hello,超哥!Hello!"
b := strings.IndexAny(s, "abc")
fmt.Println(b) //-1
b = strings.IndexAny(s, "")
fmt.Println(b) //-1
b = strings.IndexAny(s, "超")
fmt.Println(b) LastIndexAny返回字符串chars中的任何一个字符串s中最后一次出现的位置
找不到返回-,chars为空也返回-
func LastIndexAny(s, chars string) int {
s:="Hello,世界!Hello!"
b:=strings.LastIndexAny(s,"abc")
fmt.Println(b)//-1
b=strings.LastIndexAny(s,"世")
fmt.Println(b)//6 最后一次出现的索引位置
b=strings.LastIndexAny(s,"")
fmt.Println(b)//-1 }

比较全的是golang中文网的:https://studygolang.com/articles/5769

Golang之strings包的更多相关文章

  1. 19-03【golang】strings包

    golang的strings包提供了字符串操作的一系列函数.下面做个简单介绍 函数 用法 备注 Compare(a,b sring) 比较两个字符串   Contains(s, substr stri ...

  2. Golang学习 - strings 包

    ------------------------------------------------------------ strings 包与 bytes 包中的函数用法基本一样,不再赘述. 只对 R ...

  3. golang——(strings包)常用字符串操作函数

    (1)func HasPrefix(s, prefix string) bool 判断字符串s是否有前缀字符串prefix: (2)func HasSuffix(s, suffix string) b ...

  4. GoLang之strings、buffers、bytes、binary包

    strings包 strings包的使用举例: package main import s "strings" import "fmt" var p = fmt ...

  5. Golang爬虫示例包系列教程(一):pedaily.com投资界爬虫

    Golang爬虫示例包 文件结构 自己用Golang原生包封装了一个爬虫库,源码见go get -u -v github.com/hunterhug/go_tool/spider ---- data ...

  6. Go语言strings包

    目录 strings包实现了用于操作字符的简单函数. func EqualFold 判断两个utf-8编码字符串(将unicode大写.小写.标题三种格式字符视为相同)是否相同. func Equal ...

  7. strings包

    http://docscn.studygolang.com/pkg/strings/ Golang官方对strings包的介绍,strings包都是关于字符串的操作 常用的函数: 判断s1中是否包含字 ...

  8. Golang学习 - unsafe 包

    ------------------------------------------------------------ 指针类型: *类型:普通指针,用于传递对象地址,不能进行指针运算. unsaf ...

  9. 一键解决 go get golang.org/x 包失败

    问题描述 当我们使用 go get.go install.go mod 等命令时,会自动下载相应的包或依赖包.但由于众所周知的原因,类似于 golang.org/x/... 的包会出现下载失败的情况. ...

随机推荐

  1. C语言——第四次作业(2)

    作业要求一 项目wordcount 设计思路:输入需统计的文件名,打开此文件,输入功能对应的字符,分别实现对应的功能,关闭文件. 主要代码 #include<stdio.h> #inclu ...

  2. start-stop-daemon自动启动、关闭后台程序参数传递

    /************************************************************************* * start-stop-daemon自动启动.关 ...

  3. bzoj 1002 [FJOI2007]轮状病毒——打表找规律

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1002 看 Zinn 的博客:https://www.cnblogs.com/Zinn/p/9 ...

  4. git回滚分支版本到指定版本

    昨天提交代码时Eclipse凌乱了,本来拉了dev-20190201分支的,结果提交时竟然跑到dev分支了.为了把dev分支回滚,可以有两种方式:Eclipse和命令行. 先说简单的命令行方式,先用g ...

  5. opencv中读取显示图像

    opencv是个开源的图像处理的库,小到基本的图像处理函数,如图像移动放大缩小,大到人脸识别,部分机器学习的知识,所以是个学习的不错的库.之前有图像处理的知识,这次再学习下这个开源库. 先上基础的图像 ...

  6. storyboard貌似不错

    冷静下来看了下,貌似聽简单,蛋疼,忙完才发现,弄的时候咋没发现,靠 push,present等可以全部用下面这个api搞定 - (void)performSegueWithIdentifier:(NS ...

  7. JAVA面向对象编程课程设计——web版斗地主

    一.团队课程设计博客链接 JAVA面向对象编程课程设计--网络版单机斗地主 二.个人负责模块或任务说明 实体类的设计 斗地主规则的实现 人机自动出牌的算法 实现数据库的DAO模式 三.自己的代码提交记 ...

  8. mac下执行 appium-doctor 出现 “Could not detect Mac OS X Version from sw_vers output: '10.12 '” 解决方法

      You can config file by this command: grep -rl "Could not detect Mac OS X Version from sw_vers ...

  9. CFGym 101161I 题解

    一.题目链接 http://codeforces.com/gym/101161/problem/I 二.题意 给定一棵树,一个初始的省会城市,若干个询问,0表示修改省会城市,1表示查询去省会必须经过指 ...

  10. 给iOS开发新手送点福利,简述UIAlertView的属性和用法

    UIAlertView 1.Title 获取或设置UIAlertView上的标题. 2.Message 获取或设置UIAlertView上的消息 UIAlertView *alertView = [[ ...