parent
7fb169443c
commit
0059989510
2 changed files with 26 additions and 21 deletions
@ -0,0 +1,23 @@ |
||||
package utils |
||||
|
||||
import "strings" |
||||
|
||||
// Split text in chunks of almost specified size.
|
||||
func SplitTextAtChunk(text string, size int) []string { |
||||
words := strings.SplitN(text, " ", -1) |
||||
|
||||
chunks := []string{} |
||||
var message string |
||||
for _, word := range words { |
||||
|
||||
if len(message+" "+word) > size { |
||||
chunks = append(chunks, message) |
||||
message = word |
||||
continue |
||||
} |
||||
message += " " + word |
||||
} |
||||
chunks = append(chunks, message) |
||||
|
||||
return chunks |
||||
} |
Loading…
Reference in new issue