473,398 Members | 2,113 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,398 software developers and data experts.

Copy unique values to new array

Hi,

In VB.net I have an array which contains different values. For example:
array(0) = 2
array(1) = 2
array(2) = 2
array(3) = 3
array(4) = 3
array(5) = 6
array(6) = 6
array(7) = 4
array(8) = 4
array(9) = 4
I'd like to copy the unique values in this array to a new array, which
contains only these unique values. In this example arraySecond would be:
arraySecond(0) = 2
arraySecond(1) = 3
arraySecond(2) = 6
arraySecond(3) = 4

Can anyone help me with the code for creating this second array based on the
first? I cannot find a way to accomplish this.

Thanks in advance,
Joep
Nov 21 '05 #1
1 7146
Joep,

mmm... that's pure logic stuff. I have an example below, but I would think of using an ArrayList instead of a regular array. Good luck!
//
Function GetArray(ByVal array() As Integer) As Integer()

Dim x, y, n, sa() As Integer

y = -1

n = 0

array.Sort(array)

For Each x In array

If x <> y Then

ReDim Preserve sa(n)

sa(n) = x

y = x

n += 1

End If

Next

Return sa

End Function

//

Telmo Sampaio

"Joep" <je******@planet.nl> wrote in message news:cf**********@reader13.wxs.nl...
Hi,

In VB.net I have an array which contains different values. For example:
array(0) = 2
array(1) = 2
array(2) = 2
array(3) = 3
array(4) = 3
array(5) = 6
array(6) = 6
array(7) = 4
array(8) = 4
array(9) = 4
I'd like to copy the unique values in this array to a new array, which
contains only these unique values. In this example arraySecond would be:
arraySecond(0) = 2
arraySecond(1) = 3
arraySecond(2) = 6
arraySecond(3) = 4

Can anyone help me with the code for creating this second array based on the
first? I cannot find a way to accomplish this.

Thanks in advance,
Joep



Nov 21 '05 #2

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

Similar topics

0
by: Peter N. Schweitzer | last post by:
The function get_meta_tags reads a file or URL and returns an array, one element for each META tag in the HEAD element of the document. The keys of this array are the values of the name attribute...
7
by: simkn | last post by:
Hello, I'm writing a function that updates an array. That is, given an array, change each element. The trick is this: I can't change any elements until I've processed the entire array. For...
7
by: Richard Forester | last post by:
Hello. I need some help understanding what goes on when an array is copied. I create 2 arrays and copy one to the other: int pins = {9, 3, 7, 2}; int copy = new int; for (int i = 0; i !=...
1
by: jason | last post by:
NEWBIE - Hello. I've been able to do the following in other languages (perl,jscript,etc.) but am a asp.net newbie and need some help. I have this textbox that has a bunch of data in it. At the...
8
by: nescio | last post by:
hello, i have an array and i don't know the content of it, but i want only unique values. in php there is a function to do this, but how must i do this in javascript? i have tried a lot and...
5
by: Paulers | last post by:
Hello all, I have a string array with duplicate elements. I need to create a new string array containing only the unique elements. Is there an easy way to do this? I have tried looping through...
9
by: Brian Tkatch | last post by:
I'm looking for a simple way to unique an array of strings. I came up with this. Does it make sense? Am i missing anything? (Testing seems to show it to work.) Public Function Unique(ByVal...
5
by: tshad | last post by:
How do you easily make a copy of an arraylist? If you do: arrayList2 = arrayList1 You get a pointer so that if you clear arrayList2 (arrayList2.Clear) - arrayList1 is also cleared. I...
4
Ispep
by: Ispep | last post by:
Hi, unfortunately having a bit of difficulty with a question from an Open University course I'm currently doing. If you could help me out in any way I'd be grafeul (though obviously it goes without...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...
0
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...

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.