diff options
author | rsiddharth <s@ricketyspace.net> | 2020-12-20 21:00:14 -0500 |
---|---|---|
committer | rsiddharth <s@ricketyspace.net> | 2020-12-20 21:00:14 -0500 |
commit | 6a1615a635b136ec09b60ae4871056c4367832c8 (patch) | |
tree | 1f5f97ff78805a31ea2907924f538c834081b462 /lib/str.go | |
parent | e71a8f1750c2cc0fd6cbdb7048ddf5ff5ed95a7b (diff) |
lib/str: add StrSplitAt
Diffstat (limited to 'lib/str.go')
-rw-r--r-- | lib/str.go | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -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 +} |