Go语言截取字符串函数用法
本文实例讲述了Go语言截取字符串函数用法。分享给大家供大家参考。具体如下:
代码如下:
func Substr(str string, start, length int) string { rs := []rune(str) rl := len(rs) end := 0 if start < 0 { start = rl - 1 + start } end = start + length if start > end { start, end = end, start } if start < 0 { start = 0 } if start > rl { start = rl } if end < 0 { end = 0 } if end > rl { end = rl } return string(rs[start:end]) }
希望本文所述对大家的Go语言程序设计有所帮助。
相关推荐
chinawangfei 2020-06-16
文山羊 2020-10-20
Tristahong 2020-10-14
stulen 2020-08-15
xiaoseyihe 2020-08-11
amberom 2020-08-03
fengzhiwu 2020-08-01
pythonxuexi 2020-07-30
leoaran 2020-07-21
littie 2020-07-19
kkpiece 2020-07-08
zlsdmx 2020-07-05
银角大王 2020-07-05
yjsflxiang 2020-07-04
shonmark 2020-06-27
liusarazhang 2020-06-14
xiaobaif 2020-06-14