18 lines
320 B
Go
18 lines
320 B
Go
package util
|
|
|
|
import (
|
|
"regexp"
|
|
)
|
|
|
|
/*
|
|
按空格分割字符串,返回分割后的字符串数组
|
|
@param text 要分割的字符串
|
|
@param n 分割的次数
|
|
@return 分割后的字符串数组
|
|
*/
|
|
func SplitN(text string, n int) []string {
|
|
re := regexp.MustCompile(`\s+`)
|
|
tokens := re.Split(text, n)
|
|
return tokens
|
|
}
|