func GetBetweenStr(str, start, end string) string { n := strings.Index(str, start) if n == -1 { n = 0 } str = string([]byte(str)[n:]) m := strings.Index(str, end) if m == -1 { m = len(str) } str = string([]byte(str)[:m]) return str } 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]) }
golang 字符串操作 函数
有疑问加站长微信联系(非本文作者)