diff --git a/util/split.go b/util/split.go new file mode 100644 index 0000000..d231ea2 --- /dev/null +++ b/util/split.go @@ -0,0 +1,15 @@ +package util + +import ( + "regexp" +) + +func SplitN(text string, n int) ([]string, int) { + if n == 0 { + return []string{text}, 1 + } + + re := regexp.MustCompile(`\s+`) + tokens := re.Split(text, n) + return tokens, len(tokens) +}