diff --git "a/DotNet.Utilities/\345\255\227\347\254\246\344\270\262/StringHelper.cs" "b/DotNet.Utilities/\345\255\227\347\254\246\344\270\262/StringHelper.cs" index 816153639917740aa27433dc2bee5a42f15451b6..9b174e111e6487b2119a9769d1b718f28ac6da34 100644 --- "a/DotNet.Utilities/\345\255\227\347\254\246\344\270\262/StringHelper.cs" +++ "b/DotNet.Utilities/\345\255\227\347\254\246\344\270\262/StringHelper.cs" @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; @@ -21,6 +21,7 @@ namespace DotNet.Utilities /// 12、GetNewStyle(string StrList, string NewStyle, string SplitString, out string Error)将字符串转换为新样式 /// 13、SplitMulti(string str, string splitstr)分割字符串 /// 14、SqlSafeString(string String, bool IsDel) + /// 15. GetStrArray(string str, string[] speaters, bool toLower = false)把字符串按照分隔符转换成 IEnumerable /// public class StringHelper { @@ -563,5 +564,25 @@ namespace DotNet.Utilities return false; } #endregion + + /// + /// 把字符串按照分隔符转换成 IEnumerable + /// + /// 源字符串 + /// 分隔符集合 + /// 是否转换为小写,默认小写 + /// + public static IEnumerable GetStrArray(string str, string[] speaters, bool toLower = false) + { + foreach (string s in str.Split(speaters, StringSplitOptions.RemoveEmptyEntries)) + { + string temp = s.Trim(); + if (!string.IsNullOrEmpty(temp)) + { + yield return toLower ? temp.ToLower() : temp; + } + } + } + } }