searching an array list

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hey

I need to search an array list to remove duplicate Data
The list is populated by a search function that enters in a name if the it is told too

This causes duplicate names to be entered into the array, the search function is not changable

e.

the array list has 5 values "jonny", I need to remove all the values but the 1st. The array can have several differnet copies of one name

Thanks

/Jonny
 
Hi Jonny,
Check out the forum answers in this link
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20824139.html
I think it will help you

--
Rami Saad
Microsoft GTSC Developer support for Middle East


jonny said:
Hey,

I need to search an array list to remove duplicate Data.
The list is populated by a search function that enters in a name if the it is told too.

This causes duplicate names to be entered into the array, the search function is not changable.

e.g

the array list has 5 values "jonny", I need to remove all the values but
the 1st. The array can have several differnet copies of one name.
 
Hey,

I need to search an array list to remove duplicate Data.
The list is populated by a search function that enters in a name if the it is told too.

This causes duplicate names to be entered into the array, the search function is not changable.

e.g

the array list has 5 values "jonny", I need to remove all the values but the 1st. The array can have several differnet copies of one name.

Thanks,

/Jonny

One solution is to first sort the array, then loop through it. If an
items value is the same as the previous item, delete it.

HTH,
Tim
 
jonny said:
Hey,

I need to search an array list to remove duplicate Data.
The list is populated by a search function that enters in a name if the it is told too.

This causes duplicate names to be entered into the array, the search function is not changable.

e.g

the array list has 5 values "jonny", I need to remove all the values but the 1st. The array can have several differnet copies of one name.

Try this:

// filledArrayList - your ArrayList
int index;

for(int i=0; i<(filledArrayList.Count-1); i++) {
index=filledArrayList.IndexOf(filledArrayList, i+1);
while( index>i ) {
filledArrayList.Remove(index);
if( i<(filledArrayList.Count-1) ) {
index=filledArrayList.IndexOf(filledArrayList, i+1);
}
else {
index=-1;
}
}
}

Regards

Marcin
 
maybe you should use Hashtable class instead of an ArrayList?

jonny said:
Hey,

I need to search an array list to remove duplicate Data.
The list is populated by a search function that enters in a name if the it is told too.

This causes duplicate names to be entered into the array, the search function is not changable.

e.g

the array list has 5 values "jonny", I need to remove all the values but
the 1st. The array can have several differnet copies of one name.
 
Back
Top