1
0
Fork 0
Telegram bot to post messages from a Telegram group to Mastodon.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
telegram-group2mastodon/utils/text.go

23 lines
438 B

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
}