By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,216 Members | 1,443 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,216 IT Pros & Developers. It's quick & easy.

Smart Slicing Routine!!

P: n/a
Hi All, I need some smart way to accomplish this task in C# (.net 1.0)

Appreciate your inputs!!
==================================
Input ArrayList:
2,3,4,20
1,2,2
2
2,2,2
1,2,3,4
1,1
null

expected oututs:
Bundle Count=1 and the bundle will contain 2,3,4,20
Bundle Count=3 Bundle#1 wil contain 1 Bundle#2 will contain 2 and Bundle#3
will cotain 2
Bundle Count=1 Bundle#1 will contain 2
Bundle Count=3 Bundle#1 wil contain 2 Bundle#2 will contain 2 and Bundle#3
will cotain 2
Bundle Count=2 Bundle#1 wil contain 1 Bundle#2 will contain 2 ,3,4
{formatted with,}
Bundle Count =2 Bundle#1 wil contain 1 Bundle#2 will contain 1
Null
............
==================================
Jan 29 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
The answers in the other thread will do what you are after. Though seeing
this it was a poor explanation in your original post. And this one isn't too
clear either. So you have a load of array lists each with data and you want
them to be broken up into new arrays of data? Or do you want them broken up
into individual strings? strings arrays? What?

Anyway this is a guide, you do need to apply some coding skill to match your
exact requirement as no one helping knows the context of all this, so:

1) Loop your input array list
2) Get the value of an array slot and check if it is 2 or 1
3) if 2 or 1 create new array, string array whatever it is you want it as,
store it in the array
4) go to next slot, if it is not a 2 or 1 append to the created array in
step 3.
5) If it is a 2 or 1 store the array created and make a new one, store the
2/1 and repeat.

Now do that for every array list being passed in. That will work. Up to you
to apply it. If you struggle to apply it then try and post your code
attempt.
"Vai2000" <no****@microsoft.comwrote in message
news:ue*************@TK2MSFTNGP06.phx.gbl...
Hi All, I need some smart way to accomplish this task in C# (.net 1.0)

Appreciate your inputs!!
==================================
Input ArrayList:
2,3,4,20
1,2,2
2
2,2,2
1,2,3,4
1,1
null

expected oututs:
Bundle Count=1 and the bundle will contain 2,3,4,20
Bundle Count=3 Bundle#1 wil contain 1 Bundle#2 will contain 2 and Bundle#3
will cotain 2
Bundle Count=1 Bundle#1 will contain 2
Bundle Count=3 Bundle#1 wil contain 2 Bundle#2 will contain 2 and Bundle#3
will cotain 2
Bundle Count=2 Bundle#1 wil contain 1 Bundle#2 will contain 2 ,3,4
{formatted with,}
Bundle Count =2 Bundle#1 wil contain 1 Bundle#2 will contain 1
Null
...........
==================================


Jan 29 '07 #2

P: n/a
I am looking for a smart solution, I have already done it but its not a very
smart solution!!
Answers to your questions:
1. The ArrayList stores strings inside it.....
so what I showed below are contents of the arrayList...

I need tight routine!!!

TIA

"Daniel" <no****@pokercat.co.ukwrote in message
news:%2***************@TK2MSFTNGP06.phx.gbl...
The answers in the other thread will do what you are after. Though seeing
this it was a poor explanation in your original post. And this one isn't
too
clear either. So you have a load of array lists each with data and you
want
them to be broken up into new arrays of data? Or do you want them broken
up
into individual strings? strings arrays? What?

Anyway this is a guide, you do need to apply some coding skill to match
your
exact requirement as no one helping knows the context of all this, so:

1) Loop your input array list
2) Get the value of an array slot and check if it is 2 or 1
3) if 2 or 1 create new array, string array whatever it is you want it as,
store it in the array
4) go to next slot, if it is not a 2 or 1 append to the created array in
step 3.
5) If it is a 2 or 1 store the array created and make a new one, store the
2/1 and repeat.

Now do that for every array list being passed in. That will work. Up to
you
to apply it. If you struggle to apply it then try and post your code
attempt.
"Vai2000" <no****@microsoft.comwrote in message
news:ue*************@TK2MSFTNGP06.phx.gbl...
Hi All, I need some smart way to accomplish this task in C# (.net 1.0)

Appreciate your inputs!!
==================================
Input ArrayList:
2,3,4,20
1,2,2
2
2,2,2
1,2,3,4
1,1
null

expected oututs:
Bundle Count=1 and the bundle will contain 2,3,4,20
Bundle Count=3 Bundle#1 wil contain 1 Bundle#2 will contain 2 and
Bundle#3
will cotain 2
Bundle Count=1 Bundle#1 will contain 2
Bundle Count=3 Bundle#1 wil contain 2 Bundle#2 will contain 2 and
Bundle#3
will cotain 2
Bundle Count=2 Bundle#1 wil contain 1 Bundle#2 will contain 2 ,3,4
{formatted with,}
Bundle Count =2 Bundle#1 wil contain 1 Bundle#2 will contain 1
Null
...........
==================================


Jan 29 '07 #3

P: n/a
Hi,

What exactly was not smart about the solution presented in the other
thread?

Brian

On Jan 29, 1:35 pm, "Vai2000" <nos...@microsoft.comwrote:
I am looking for a smart solution, I have already done it but its not a very
smart solution!!
Answers to your questions:
1. The ArrayList stores strings inside it.....
so what I showed below are contents of the arrayList...

I need tight routine!!!

TIA
Jan 29 '07 #4

P: n/a
Sadly No! Dont worry about it...I finally wrote it myself
===================================

for(int idx=0;idx<alNonBundle.Count;idx++)
{
str=alNonBundle[idx];

if(str.Equals("2") || str.Equals("1"))
{
pos=idx;

CopyArray(lastpos,pos,alNonBundle);

lastpos=pos;
}

}
void CopyArray(int spos,int epos,ArrayList al)
{
string []arr=new string[epos-spos];
al.CopyTo(spos,arr,0,epos-spos);
}

"Brian Gideon" <br*********@yahoo.comwrote in message
news:11**********************@l53g2000cwa.googlegr oups.com...
Hi,

What exactly was not smart about the solution presented in the other
thread?

Brian

On Jan 29, 1:35 pm, "Vai2000" <nos...@microsoft.comwrote:
I am looking for a smart solution, I have already done it but its not a
very
smart solution!!
Answers to your questions:
1. The ArrayList stores strings inside it.....
so what I showed below are contents of the arrayList...

I need tight routine!!!

TIA

Jan 29 '07 #5

P: n/a
Hi,

Are you sure that's right? That code doesn't produce any side
effects. Seems like the following is more of what you want.

public IList Partition(IList input)
{
IList output = new ArrayList();
IList bundle = new ArrayList();
foreach (string item in input)
{
if (bundle.Count 0 && (item == "1" || item == "2"))
{
output.Add(bundle);
bundle = new ArrayList();
}
bundle.Add(item);
}
output.Add(bundle);
return output;
}

Brian

On Jan 29, 2:31 pm, "Vai2000" <nos...@microsoft.comwrote:
Sadly No! Dont worry about it...I finally wrote it myself
===================================

for(int idx=0;idx<alNonBundle.Count;idx++)
{
str=alNonBundle[idx];

if(str.Equals("2") || str.Equals("1"))
{
pos=idx;

CopyArray(lastpos,pos,alNonBundle);

lastpos=pos;
}

}void CopyArray(int spos,int epos,ArrayList al)
{
string []arr=new string[epos-spos];
al.CopyTo(spos,arr,0,epos-spos);

}
Jan 29 '07 #6

P: n/a
You actually tried? For yourself! Gasp! Surely not..... Word of advice and
friendly tip. Don't use exclamation marks when asking for help, try not to
be rude about help you are given and be respectful of others.

"Vai2000" <no****@microsoft.comwrote in message
news:%2******************@TK2MSFTNGP03.phx.gbl...
Sadly No! Dont worry about it...I finally wrote it myself
===================================

for(int idx=0;idx<alNonBundle.Count;idx++)
{
str=alNonBundle[idx];

if(str.Equals("2") || str.Equals("1"))
{
pos=idx;

CopyArray(lastpos,pos,alNonBundle);

lastpos=pos;
}

}
void CopyArray(int spos,int epos,ArrayList al)
{
string []arr=new string[epos-spos];
al.CopyTo(spos,arr,0,epos-spos);
}

"Brian Gideon" <br*********@yahoo.comwrote in message
news:11**********************@l53g2000cwa.googlegr oups.com...
>Hi,

What exactly was not smart about the solution presented in the other
thread?

Brian

On Jan 29, 1:35 pm, "Vai2000" <nos...@microsoft.comwrote:
I am looking for a smart solution, I have already done it but its not a
very
smart solution!!
Answers to your questions:
1. The ArrayList stores strings inside it.....
so what I showed below are contents of the arrayList...

I need tight routine!!!

TIA


Jan 29 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.