SubString for go (works well with unicode)

Dec 12, 2019
// SubString works well with unicode
func SubString(str string, start int, length int) string {
	r := []rune(str)
	n := len(r)
	if start >= n || length <= 0 {
		return ""
	}

	if start < 0 {
		start = 0
	}
	end := start + length
	if end > n {
		end = n
	}

	return string(r[start:end])
}