根据字符串拆分字符串
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 6 namespace SINOStockBL 7 { 8 public class StrSplitHelp 9 { 10 #region 拆分字符串 11 /// <summary> 12 /// 根据字符串拆分字符串 13 /// </summary> 14 /// <param name="strSource">要拆分的字符串</param> 15 /// <param name="strSplit">拆分符</param> 16 /// <returns></returns> 17 public static string[] StringSplit(string strSource, string strSplit) 18 { 19 string[] strtmp = new string[1]; 20 int index = strSource.IndexOf(strSplit, 0); 21 if (index < 0) 22 { 23 strtmp[0] = strSource; 24 return strtmp; 25 } 26 else 27 { 28 strtmp[0] = strSource.Substring(0, index); 29 return StringSplit(strSource.Substring(index + strSplit.Length), strSplit, strtmp); 30 } 31 } 32 #endregion 33 34 #region 采用递归将字符串分割成数组 35 /// <summary> 36 /// 采用递归将字符串分割成数组 37 /// </summary> 38 /// <param name="strSource"></param> 39 /// <param name="strSplit"></param> 40 /// <param name="attachArray"></param> 41 /// <returns></returns> 42 private static string[] StringSplit(string strSource, string strSplit, string[] attachArray) 43 { 44 string[] strtmp = new string[attachArray.Length + 1]; 45 attachArray.CopyTo(strtmp, 0); 46 47 48 int index = strSource.IndexOf(strSplit, 0); 49 if (index < 0) 50 { 51 strtmp[attachArray.Length] = strSource; 52 return strtmp; 53 } 54 else 55 { 56 strtmp[attachArray.Length] = strSource.Substring(0, index); 57 return StringSplit(strSource.Substring(index + strSplit.Length), strSplit, strtmp); 58 } 59 } 60 #endregion 61 } 62 }
Android 成长之路