字符串扩展分割增加了自定义分隔符参数。
This commit is contained in:
parent
2e1a0ad0c0
commit
0064ceda3d
|
@ -12,19 +12,21 @@ namespace Falcon.SugarApi
|
|||
/// </summary>
|
||||
/// <param name="str">字符串</param>
|
||||
/// <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>
|
||||
/// 字符串是否不为空或null
|
||||
/// </summary>
|
||||
/// <param name="str">字符串</param>
|
||||
/// <returns>与IsNullOrEmpty相反</returns>
|
||||
public static bool IsNotNullOrEmpty(this string str) => !str.IsNullOrEmpty();
|
||||
public static bool IsNotNullOrEmpty(this string? str) => !str.IsNullOrEmpty();
|
||||
|
||||
/// <summary>
|
||||
/// 使用全角半角的逗号句号和分号分割字符串。
|
||||
/// </summary>
|
||||
/// <param name="str">要分割的字符串</param>
|
||||
/// <param name="splitChars"></param>
|
||||
/// <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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user