Re: Slicing Routine!



Two approaches here, the first returns an arraylist of the starting
points of each segment, and the second returns an arraylist of
arraylists containing each segment.

private void button1_Click(object sender, System.EventArgs e)
{
ArrayList a = new ArrayList();

int[] i = new int[] {2,3,5,2,1,2,2,3};
a.AddRange(i);
ArrayList b = DoIt2(a);
ArrayList c = DoIt(a);
Console.WriteLine(".");
}
private ArrayList DoIt(ArrayList pList)
{
ArrayList a = new ArrayList();
for(int c=0;c<pList.Count;c++)
{
if(1 == (int)pList[c] || 2 == (int)pList[c])
{
a.Add(c);
}
}
return a;
}
private ArrayList DoIt2(ArrayList pList)
{
ArrayList a = new ArrayList();
ArrayList b = null;
for(int c=0;c<pList.Count;c++)
{
if(1 == (int)pList[c] || 2 == (int)pList[c])
{
if(null == b)
{
b = new ArrayList();
}
else
{
b = new ArrayList();
}
a.Add(b);
}
b.Add(pList[c]);
}
return a;
}



On 29 Jan, 16:12, "Vai2000" <nos...@xxxxxxxxxxxxx> wrote:
Hi All, I am looking for a smart solution to accomplish this task (.net 1.0)
Appreciate your input

I have a group of numbers in an arrayList
2,3,5,2,1,2,2

I need to output them into groups of
2,3,5
2
1
2
2

basically whenever I encounter 1 or 2 I bundle them up..

The numbers are in an arrayList, and I output them as string []

Arraylist Bundle(Arraylist)
{
// arr1 will contain (2,3,5)
alReturn.Add(arr1);
..................
return alReturn

}TIA

.