diff --git a/string_util.go b/string_util.go index 5ef9d84..14cf4e2 100644 --- a/string_util.go +++ b/string_util.go @@ -81,3 +81,23 @@ func StringSliceContains(slice []string, s string) bool { } return false } + +func StringAt(s string, index int) string { + if len(s)-1 < index || index < 0 { + return "" + } + + return string(s[index]) +} + +func SplitStringAfterN(s string, n, count int) (parts []string) { + rem := s + i := 0 + for len(rem) > n && (i < count || count < 0) { + parts = append(parts, rem[0:n]) + rem = rem[n:] + i++ + } + parts = append(parts, rem) + return parts +}