首页 > 其他 > 详细

分割字符串

时间:2016-08-25 23:25:13      阅读:228      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!