From 3404365b0b23298ae35646db5fad569d81de1b6b Mon Sep 17 00:00:00 2001
From: falcon <9504402@qq.com>
Date: Tue, 29 Mar 2022 16:14:07 +0800
Subject: [PATCH] =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E6=89=A9=E5=B1=95?=
=?UTF-8?q?=E6=96=B9=E6=B3=95SplitStr=E4=BC=9A=E5=8E=BB=E6=8E=89=E7=A9=BA?=
=?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E5=92=8C=E6=AF=8F=E4=B8=AA=E5=88=86?=
=?UTF-8?q?=E5=89=B2=E5=AD=97=E7=AC=A6=E4=B8=B2=E4=B8=A4=E7=AB=AF=E7=A9=BA?=
=?UTF-8?q?=E6=A0=BC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Falcon.SugarApi.Test/StringExtendTest.cs | 6 ++++++
Falcon.SugarApi/StringExtend.cs | 2 +-
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/Falcon.SugarApi.Test/StringExtendTest.cs b/Falcon.SugarApi.Test/StringExtendTest.cs
index 2613f83..918b910 100644
--- a/Falcon.SugarApi.Test/StringExtendTest.cs
+++ b/Falcon.SugarApi.Test/StringExtendTest.cs
@@ -16,6 +16,12 @@ namespace Falcon.SugarApi.Test
var str = $"a,b.c;d,e。f;g";
var strArr = str.SplitStr();
Assert.AreEqual(7, strArr.Length, "分割后长度应该为7");
+ str = "a,,, ,b ,c c,";
+ strArr = str.SplitStr();
+ Assert.AreEqual(3, strArr.Length, "分割后长度应该为3");
+ Assert.AreEqual("a", strArr[0]);
+ Assert.AreEqual("b", strArr[1]);
+ Assert.AreEqual("c c", strArr[2]);
str = null;
strArr = str.SplitStr();
Assert.IsNotNull(strArr);
diff --git a/Falcon.SugarApi/StringExtend.cs b/Falcon.SugarApi/StringExtend.cs
index cc4cb27..d165a8b 100644
--- a/Falcon.SugarApi/StringExtend.cs
+++ b/Falcon.SugarApi/StringExtend.cs
@@ -25,6 +25,6 @@ namespace Falcon.SugarApi
///
/// 要分割的字符串
/// 字符串数组。当str为null时返回空数组
- public static string[] SplitStr(this string? str) => str == null ? Array.Empty() : str.Split(new char[] { ',', ',', ';', ';', '.', '。' });
+ public static string[] SplitStr(this string? str) => str == null ? Array.Empty() : str.Split(new char[] { ',', ',', ';', ';', '.', '。' }, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
}
}