From 003c9b6f9014095747b758768025f0e125dcaf2c Mon Sep 17 00:00:00 2001 From: lixiangwuxian Date: Sun, 20 Oct 2024 14:34:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=88=87=E5=88=86?= =?UTF-8?q?=E6=96=87=E6=9C=AC=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- util/split.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 util/split.go diff --git a/util/split.go b/util/split.go new file mode 100644 index 0000000..d231ea2 --- /dev/null +++ b/util/split.go @@ -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) +}