码迷,mamicode.com
首页 > 其他好文 > 详细

分割字符串

时间:2016-08-25 23:27:37      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:

#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
技术分享

分割字符串

标签:

原文地址:http://www.cnblogs.com/zhangxiaolei521/p/5808516.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!