473,748 Members | 2,891 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 8496
An easy method

Hashtable strings = new Hashtable();
// Add strings to strings, using strings[stringName]
ArrayList stringArray = new ArrayList(strin gs.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_@_nosp am_.com> wrote in message
news:5d******** *************** *********@4ax.c om...
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_@_nosp am_.com> wrote in message
news:5d******** *************** *********@4ax.c om...
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.Collecti ons.ArrayList a;
for ( ... )
{
if (!a.Contains(va lue))
a.Add(value);
}
return (string[]) a.ToArray(typeo f(string));

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

Hashtable strings = new Hashtable();
// Add strings to strings, using strings[stringName]
ArrayList stringArray = new ArrayList(strin gs.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
7816
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 in this array and the number of times it has been duplicated. can someone help?
3
3149
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 three. The most straightforward way I can think of is to first swap every member such that every member has its key smaller than its value. Then loop thru the multipmap and erase duplicates (please see the loop below). Is there a more automatic way...
7
7286
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? STL set, map? Could you give me a little code example? Thank you.
3
2734
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 Name Company Town Alan ABC Alphaville Brian B inc. Beta City Calan ABC Alpaville
1
1420
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
5838
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 using the split function with ' ', but how do i get it to take into account punctuation marks such as ',',',' etc? Also I am then trying to add contents of an array of strings to an arraylist, but only if the string isn't already there. I was using...
3
2579
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
12970
by: ak | last post by:
Is it possible to find repeated(duplicate) element in an array in single loop ? AK
3
25077
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 compare a to b. If they're different then it will print out 'duplicates found'. The problem is that even after trying different arrays, some with duplicates some without, that 'b' rearranges the numbers. Here's an example: a='1934, 2311,...
0
8826
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9366
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9241
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8239
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3303
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2777
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2211
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.