From 6a1615a635b136ec09b60ae4871056c4367832c8 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sun, 20 Dec 2020 21:00:14 -0500 Subject: lib/str: add StrSplitAt --- lib/str.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/str.go b/lib/str.go index 6938bfd..c93ca12 100644 --- a/lib/str.go +++ b/lib/str.go @@ -99,3 +99,20 @@ func NumToStr(n int64) string { return s } +func StrSplitAt(c byte, s string) []string { + l := make([]string, 0) + + acc := "" + for i := 0; i < len(s); i++ { + if s[i] == c { + l = append(l, acc) + acc = "" + } else { + acc += string(s[i]) + } + } + if len(acc) > 0 { + l = append(l, acc) + } + return l +} -- cgit v1.2.3