Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


removing duplicate array values

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,27947
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> removing duplicate array values
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 removing duplicate array values - 11/11/2005 4:26:03 AM   
  needhelper

 

Posts: 2
Score: 0
Joined: 11/11/2005
Status: offline
Hello,

Please forgive me for this in advance, as this question may be straightforward.  I'm a beginnner and need some assistance with the following:

I have a simple, one-dimensional array filled with text values such as:

some text here
more text
moretexthere
some text here
..
...
...
etc.

I need to remove the duplicate text values from the array before writing it to a file.  In the above, 'some text here' would need to be removed.  Please advise, I can't seem to figure this out.

Thanks!
 
 
Post #: 1
 
 RE: removing duplicate array values - 11/11/2005 4:55:16 AM   
  ehvbs

 

Posts: 2204
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi needhelper,

have a look at

   http://www.visualbasicscript.com/m_23980/mpage_1/key_array%2cmerge/tm.htm#23988

(in reply to needhelper)
 
 
Post #: 2
 
 RE: removing duplicate array values - 11/11/2005 5:27:04 AM   
  needhelper

 

Posts: 2
Score: 0
Joined: 11/11/2005
Status: offline
Thanks for the reference, but I only have one, one dimensional array.  Your post relates to merging multiple arrays.....please advise.  Sorry, I'm very new.

Thanks.

(in reply to ehvbs)
 
 
Post #: 3
 
 RE: removing duplicate array values - 11/11/2005 3:23:34 PM   
  TNO


Posts: 1302
Score: 12
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
vbscript is extremely efficient at handling small arrays (arrays with less than about 20000 elements). Twice as fast as jscript even.

The following will remove duplicates from a comma delimited list:


      


If your arrays become extremely large I advise against using VBScript, JavaScript/JScript is more efficient at these sizes:



      


_____________________________

To iterate is human, to recurse divine. -- L. Peter Deutsch

(in reply to needhelper)
 
 
Post #: 4
 
 RE: removing duplicate array values - 11/11/2005 7:39:31 PM   
  ehvbs

 

Posts: 2204
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi Needhelper,

this code


      
was generated from the merge sample by deleting the lines not needed.

(in reply to needhelper)
 
 
Post #: 5
 
 RE: removing duplicate array values - 11/12/2005 9:18:05 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
a quick and easy way to check for duplicates is to use the scripting.dictionary

_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to ehvbs)
 
 
Post #: 6
 
 RE: removing duplicate array values - 11/13/2005 7:33:29 PM   
  ginolard


Posts: 1068
Score: 21
Joined: 8/10/2005
Status: offline
Kirrilian is right.  If you just want a simple 2-dimensional array then take a look at the Dictionary object, I find myself using it more and more often.

(in reply to kirrilian)
 
 
Post #: 7
 
 RE: removing duplicate array values - 11/15/2005 2:39:35 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
i ran some tests with a dictionary vs an array. the dictionary beat it hands down every time in every test. even if its a one dimensional array, i just fill the key value with a sequence of numbers and use a dictionary if i know my values are going to be dynamic or checked against alot.

reference:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/jsobjDictionary.asp

_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to ginolard)
 
 
Post #: 8
 
 RE: removing duplicate array values - 11/5/2008 6:55:38 AM   
  ThePariah

 

Posts: 24
Score: 0
Joined: 6/14/2005
From: United Kingdom
Status: offline
So if it is possible to remove duplicates in an array is it possible to replace a value in an array.

Let me explain, if i read a delimited text file into an array is it possible to search for a value in that array, replace it with another value and then write that array back to the delimited  text file. Ive managed to do it but what results is all the original data in the text file is over written and where there was once many lines of delimited data im left with the one line of data that i read into the array.

(in reply to kirrilian)
 
 
Post #: 9
 
 RE: removing duplicate array values - 11/5/2008 7:52:47 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: online
I'm sure it would be possible, but I would need example data to explain exactly how.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ThePariah)
 
 
Post #: 10
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> removing duplicate array values Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts