feat: 添加切分文本功能
This commit is contained in:
parent
67cff69184
commit
003c9b6f90
15
util/split.go
Normal file
15
util/split.go
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"regexp"
|
||||||
|
)
|
||||||
|
|
||||||
|
func SplitN(text string, n int) ([]string, int) {
|
||||||
|
if n == 0 {
|
||||||
|
return []string{text}, 1
|
||||||
|
}
|
||||||
|
|
||||||
|
re := regexp.MustCompile(`\s+`)
|
||||||
|
tokens := re.Split(text, n)
|
||||||
|
return tokens, len(tokens)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user