分割字符串

#region 分割字符串
 2         /// <summary>
 3         /// 分割字符串
 4         /// </summary>
 5         public static string[] SplitString(string strContent, string strSplit)
 6         {
 7             if (!string.IsNullOrEmpty(strContent))
 8             {
 9                 if (strContent.IndexOf(strSplit) < 0)
10                     return new string[] { strContent };
11 
12                 return Regex.Split(strContent, Regex.Escape(strSplit), RegexOptions.IgnoreCase);
13             }
14             else
15                 return new string[0] { };
16         }
17 
18         /// <summary>
19         /// 分割字符串
20         /// </summary>
21         /// <returns></returns>
22         public static string[] SplitString(string strContent, string strSplit, int count)
23         {
24             string[] result = new string[count];
25             string[] splited = SplitString(strContent, strSplit);
26 
27             for (int i = 0; i < count; i++)
28             {
29                 if (i < splited.Length)
30                     result[i] = splited[i];
31                 else
32                     result[i] = string.Empty;
33             }
34 
35             return result;
36         }
37         #endregion
复制代码
原文地址:https://www.cnblogs.com/zhangxiaolei521/p/5808516.html