refactor: 在 SplitN 函数中添加字符串修剪功能,去除文本开头的空格,以增强分割功能的准确性
This commit is contained in:
parent
c434a3f0ce
commit
29f901a565
@ -2,6 +2,7 @@ package util
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
/*
|
||||
@ -11,6 +12,7 @@ import (
|
||||
@return 分割后的字符串数组
|
||||
*/
|
||||
func SplitN(text string, n int) []string {
|
||||
text = strings.TrimLeft(text, " ")
|
||||
re := regexp.MustCompile(`\s+`)
|
||||
tokens := re.Split(text, n)
|
||||
return tokens
|
||||
|
Loading…
x
Reference in New Issue
Block a user