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); } }