C# 字符串分割

 1 public string[] StringSplit(string strSource, string strSplit)
 2         {
 3             string[] strtmp = new string[1]; int index = strSource.IndexOf(strSplit, 0);
 4             if (index < 0) { strtmp[0] = strSource; return strtmp; }
 5             else
 6             {
 7                 strtmp[0] = strSource.Substring(0, index);
 8                 return StringSplit(strSource.Substring(index + strSplit.Length), strSplit, strtmp);
 9             }
10         }
11 
12         private string[] StringSplit(string strSource, string strSplit, string[] attachArray)
13         {
14             string[] strtmp = new string[attachArray.Length + 1]; attachArray.CopyTo(strtmp, 0);
15             int index = strSource.IndexOf(strSplit, 0);
16             if (index < 0)
17             {
18                 strtmp[attachArray.Length] = strSource;
19                 return strtmp;
20             }
21             else
22             {
23                 strtmp[attachArray.Length] = strSource.Substring(0, index);
24                 return StringSplit(strSource.Substring(index + strSplit.Length), strSplit, strtmp);
25             }
26         }
View Code

 

posted @ 2013-05-29 21:49  东少  阅读(196)  评论(0编辑  收藏  举报