C#中字符串分割
有时我们需将一个字符串用另一个字符串来分割成字符串字组。而C#中string.split只提供用char来分割。怎么办?
用的时候直接调用第一个函数。

 

 strSplit)
{
string[] strtmp = new string[1];
int index = strSource.IndexOf(strSplit,0);
if(index<0)
{
strtmp[
0] = strSource;
return strtmp;
}
else
{
strtmp[
0] = strSource.Substring(0,index);
return StringSplit(strSource.Substring(index+strSplit.Length),strSplit,strtmp);
}
}
[] attachArray)
{
string[] strtmp = new string[attachArray.Length+1];
attachArray.CopyTo(strtmp,
0);

int index = strSource.IndexOf(strSplit,0);
if(index<0)
{
strtmp[attachArray.Length]
= strSource;
return strtmp;
}
else
{
strtmp[attachArray.Length]
= strSource.Substring(0,index);
return StringSplit(strSource.Substring(index+strSplit.Length),strSplit,strtmp);
}
}

 


相关文章: