You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
457 B
Go
25 lines
457 B
Go
package notifications
|
|
|
|
import "bytes"
|
|
|
|
// SplitSubN splits a string into a list of string with each having
|
|
// a maximum number of characters n
|
|
func SplitSubN(s string, n int) []string {
|
|
sub := ""
|
|
subs := []string{}
|
|
|
|
runes := bytes.Runes([]byte(s))
|
|
l := len(runes)
|
|
for i, r := range runes {
|
|
sub = sub + string(r)
|
|
if (i+1)%n == 0 {
|
|
subs = append(subs, sub)
|
|
sub = ""
|
|
} else if (i + 1) == l {
|
|
subs = append(subs, sub)
|
|
}
|
|
}
|
|
|
|
return subs
|
|
}
|