码迷,mamicode.com
首页 > 其他好文 > 详细

go字符串操作

时间:2018-05-10 01:04:29      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:头部   串操作   c split   重复   通过   标准库   去除   nta   nbsp   

在Go语言标准库中的strings和strconv两个包可以对字符串做快速处理

string包

func Contains(s, substr string) bool

字符串s中是否包含substr,返回bool值

func Join(a []string, sep string) string

  字符串链接,把slice a通过sep链接起来

func Index(s, sep string) int

  在字符串s中查找sep所在的位置,返回位置值,找不到返回-1

func Repeat(s string, count int) string

  重复s字符串count次,最后返回重复的字符串

func Replace(s, old, new string, n int) string

  在s字符串中,把old字符串替换为new字符串,n表示替换的次数,小于0表示全部替换

func Split(s, sep string) []string

  把s字符串按照sep分割,返回slice

func Trim(s string, cutset string) string

  在s字符串的头部和尾部去除cutset指定的字符串

func Fields(s string) []string

  去除s字符串的空格符,并且按照空格分割返回slice

 

go字符串操作

标签:头部   串操作   c split   重复   通过   标准库   去除   nta   nbsp   

原文地址:https://www.cnblogs.com/esiarp/p/9017462.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!