473,407 Members | 2,315 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Eliminate duplicates in string array

I'm building an array of strings on the fly from a database. What is
the best method for eliminating duplicates? (I can do this before or
after the strings are added to the array)

Nov 15 '05 #1
3 8476
An easy method

Hashtable strings = new Hashtable();
// Add strings to strings, using strings[stringName]
ArrayList stringArray = new ArrayList(strings.Keys);

You can stay with the string array or convert it down to an actual array.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

"_eddie_" <_nomail_@_nospam_.com> wrote in message
news:5d********************************@4ax.com...
I'm building an array of strings on the fly from a database. What is
the best method for eliminating duplicates? (I can do this before or
after the strings are added to the array)

Nov 15 '05 #2
"_eddie_" <_nomail_@_nospam_.com> wrote in message
news:5d********************************@4ax.com...
I'm building an array of strings on the fly from a database. What is
the best method for eliminating duplicates? (I can do this before or
after the strings are added to the array)


There's a number of ways to do it. Here's a simple one:

System.Collections.ArrayList a;
for ( ... )
{
if (!a.Contains(value))
a.Add(value);
}
return (string[]) a.ToArray(typeof(string));

Erik
Nov 15 '05 #3
On Mon, 2 Feb 2004 22:28:51 -0800, "Justin Rogers"
<Ju****@games4dotnet.com> wrote:
An easy method

Hashtable strings = new Hashtable();
// Add strings to strings, using strings[stringName]
ArrayList stringArray = new ArrayList(strings.Keys);

You can stay with the string array or convert it down to an actual array.


Perfect. I had tried a hashtable, but I had more steps than necessary
(which may have accounted for some of the speed problems).

Thanks, Justin.
e
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Michelle | last post by:
hi, i have created an array from recordset containing user names eg. (davidp, davidp, evenf, patricka, rebeccah) which i have sorted in alphabetical order, but i need to identify duplicates...
3
by: Tony Young | last post by:
Hi, I have a multimap container. I want to eliminate all "duplicate" elements. By duplicate I mean something like (3, 4), (4, 3) and (4, 3), in which I want to eliminate any two of these...
7
by: eric.gagnon | last post by:
In a program randomly generating 10 000 000 alphanumeric codes of 16 characters in length (Ex.: "ZAZAZAZAZAZAZ156"), what would be an efficient way to ensure that I do not generate duplicates? ...
3
by: Quack Boy | last post by:
I'm new to MS Access (97) and I need for a query to find *near* matches (not exact duplicates) mainly to weed out duplicates that may contain similar erronious data. EG Table1 ...
1
by: GB | last post by:
Hello: I have a table like this: ID | AccNo -------------------------------- 1 0059 2 0059 3 0059 4 0194 5 0194
11
by: steve smith | last post by:
Hi I'm still having some problems getting my head round this language. A couple of things don't seem to work for me. First I am trying to obtan a count of the number of words in a sting, so am...
3
by: italia | last post by:
I have a database with 2 columns and more than million rows. The first column is the id Example of the data (2 columns)- 04731 CRM 04731 CRM 04731 CRM 04731 RVB 04731 RVB
14
by: ak | last post by:
Is it possible to find repeated(duplicate) element in an array in single loop ? AK
3
Thekid
by: Thekid | last post by:
I'm trying to figure out a way to find if there are duplicates in an array. My idea was to take the array as 'a' and make a second array as 'b' and remove the duplicates from 'b' using 'set' and then...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.