23 lines
515 B
Go
23 lines
515 B
Go
package stringutils
|
|
|
|
import "github.com/fonchain_enterprise/fonchain-main/pkg/utils/mathutils"
|
|
|
|
// 按指定长度截取文本
|
|
func SplitText(text string, length int) (textS []string) {
|
|
if text == "" {
|
|
return
|
|
}
|
|
runes := []rune(text)
|
|
runeLen := len(runes)
|
|
if runeLen <= length {
|
|
textS = append(textS, text)
|
|
return
|
|
}
|
|
nums := mathutils.NumDivCeil(runeLen, length)
|
|
for i := 0; i < nums; i++ {
|
|
end := mathutils.Min((i+1)*length, runeLen)
|
|
textS = append(textS, string(runes[i*length:end]))
|
|
}
|
|
return
|
|
}
|