using UnityEngine; using System.Collections; using System.Collections.Generic; namespace Thousandto.Plugins.Common { /// /// 字符串解析工具 /// public class SplitUtils { /// /// 字符串解析函数 /// /// /// /// public static List AnalysisStr(char[] cs, string str) { int index = 0; List list = new List(); List resultList = null; if (cs.Length > 0) { while (index < cs.Length) { if (index == 0) { string[] strs = str.Split(cs[0]); for (int i = 0; i < strs.Length; i++) { list.Add(strs[i]); } if (cs.Length == 1) { //赋值 AnalysisStr(cs[0], list, ref index, true, out resultList); } else { index += 1; } } else { if (cs.Length - 1 == index) { AnalysisStr(cs[index], list, ref index, true, out resultList); } else { list = AnalysisStr(cs[index], list, ref index, false, out resultList); } } } } return resultList; } public static List AnalysisStr(char c, List list, ref int index, bool isfnish, out List resultList) { resultList = new List(); List reList = new List(); for (int i = 0; i < list.Count; i++) { Analysis_Str data = null; string[] strs = list[i].Split(c); if (isfnish) { data = new Analysis_Str(); data.param = new int[strs.Length]; } for (int j = 0; j < strs.Length; j++) { if (!isfnish) { reList.Add(strs[j]); } else { int.TryParse(strs[j], out data.param[j]); } } if (data != null) resultList.Add(data); } index += 1; return reList; } public class Analysis_Str { public int[] param = null; } } }