字符串扩展分割增加了自定义分隔符参数。

This commit is contained in:
falcon 2022-05-24 10:33:53 +08:00
parent 2e1a0ad0c0
commit 0064ceda3d

View File

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