97 lines
3.0 KiB
C#
97 lines
3.0 KiB
C#
|
using UnityEngine;
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
|
|||
|
namespace Thousandto.Plugins.Common
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 字符串解析工具
|
|||
|
/// </summary>
|
|||
|
public class SplitUtils
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 字符串解析函数
|
|||
|
/// </summary>
|
|||
|
/// <param name="cs"></param>
|
|||
|
/// <param name="str"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public static List<Analysis_Str> AnalysisStr(char[] cs, string str)
|
|||
|
{
|
|||
|
int index = 0;
|
|||
|
List<string> list = new List<string>();
|
|||
|
List<Analysis_Str> 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<string> AnalysisStr(char c, List<string> list, ref int index, bool isfnish, out List<Analysis_Str> resultList)
|
|||
|
{
|
|||
|
resultList = new List<Analysis_Str>();
|
|||
|
List<string> reList = new List<string>();
|
|||
|
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;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|