diff --git a/Falcon.SugarApi/StringExtend.cs b/Falcon.SugarApi/StringExtend.cs index d165a8b..41ee913 100644 --- a/Falcon.SugarApi/StringExtend.cs +++ b/Falcon.SugarApi/StringExtend.cs @@ -12,19 +12,21 @@ namespace Falcon.SugarApi /// /// 字符串 /// 空或null为True,否则False - public static bool IsNullOrEmpty(this string str) => str == null || string.IsNullOrEmpty(str); + public static bool IsNullOrEmpty(this string? str) => str == null || string.IsNullOrEmpty(str); /// /// 字符串是否不为空或null /// /// 字符串 /// 与IsNullOrEmpty相反 - public static bool IsNotNullOrEmpty(this string str) => !str.IsNullOrEmpty(); + public static bool IsNotNullOrEmpty(this string? str) => !str.IsNullOrEmpty(); /// /// 使用全角半角的逗号句号和分号分割字符串。 /// /// 要分割的字符串 + /// /// 字符串数组。当str为null时返回空数组 - public static string[] SplitStr(this string? str) => str == null ? Array.Empty() : str.Split(new char[] { ',', ',', ';', ';', '.', '。' }, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); + public static string[] SplitStr(this string? str, params char[] splitChars) + => str.IsNullOrEmpty() ? Array.Empty() : str.Split(splitChars.Length == 0 ? new char[] { ',', ',', ';', ';', '.', '。' } : splitChars, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); } }