数组等量分隔成几个
如
string[] oldArray=new string[]{1,2,3,4,5,6,7,8,9}
string[] newArray=Splice(oldArray,',',3);
分隔后
newArray[0]={1,2,3};
newArray[1]={4,5,6};
newArray[2]={7,8,9};
private static string[] Splice(string[] oldArray, char splitChar, int length)
{
string[] ret;
int count = oldArray.Length;
if (count > length)
{
int num = count / length;
if (count % length > 0)
{
num++;
}
ret = new string[num];
for (int i = 0; i < num; i++)
{
int m = 0;
StringBuilder sb = new StringBuilder();
for (int j = i * length; j < count; j++)
{
sb.Append(oldArray[j] + splitChar);
m++;
if (m == length)
{
break;
}
}
ret[i] = sb.ToString().TrimEnd(splitChar);
sb = null;
}
}
else
{
ret = new string[1];
ret[0] = string.Join(splitChar.ToString(), oldArray);
}
return ret;
}