//定义需要截取的字符串
string str ="123|456|789|000";
//调用StrSpilt方法
string [] strs = StrSpilt(str,"|");
//递归处理
public string[] StrSpilt(string strSouce,string spil)
{
string [] strTemp = new String[1];
int index = strSouce.indexOf(spil,0);
if(index<0)
{
strTemp[0] = strSouce;
return strTemp;
}
else
{
strTemp[0] = strSource.subString(0,index);
return StringSpilt(strSource.Substring(index+spil.length),spil,strTemp);
}
}
public String[] StringSpilt(string strSource, string strSplit, string[] temp)
{
string [] arrays = new string[temp.length+1];
temp.CopyTo(arrays,0);
int index = strSource.IndexOf(strSpilt,0);
if(index<0)
{
arrays[temp.length] = strSource;
return arrays;
}
else
{
arrays[temp.length] = strSource.Substring(0,index);
return StringSpilt(strSource.Substring(index+strSpilt.Length),strSpilt,arrays);
}
}
递归算法获取截取的所有需要内容
最新推荐文章于 2020-08-05 12:19:39 发布