473,498 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

removing repeats from an array

i have an array of string values

i have tried all day to figure a sub that will remove them but everything i
have tried only leaves me with one item in the array.

any ideas.

Thanks in advance

WStoreyII
Nov 20 '05 #1
3 1365
* "WStoreyII" <pa**********@sbcglobal.net> scripsit:
i have an array of string values

i have tried all day to figure a sub that will remove them but everything i
have tried only leaves me with one item in the array.


Loop through the strings, then add them to a hashtable (strings as key
and value). After doing that, put all values from the hashtable back in
an array.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2
Cor
Hi WStorey,

I never used it, but I remember me an answer from Dominique, who told to use
for this the sortedlist.

http://msdn.microsoft.com/library/de...classtopic.asp

I hope this helps?

Cor
Nov 20 '05 #3
WStoreyII,

Below is a sample VB.Net console application that copies only the non-repeating strings to a new array.

I hope it helps.
Imports System
Imports System.Collections

Public Class SamplesArray

Public Shared Sub Main()
Dim i As Integer
Dim j As Integer
' Creates and initializes a new Array
Dim myArr As [String]() = {"over", "fox", "lazy", "dogs", "brown", "the", "the", _
"brown", "the", "lazy", "jumped", "dogs", "The", "the", "fox", "over", _
"quick", "brown", "lazy", "dogs", "quick", "fox", "The", "fox", "The", _
"over", "jumped", "dogs", "over", "brown", "quick", "lazy", "jumped", _
"The", "jumped", "quick"}
Dim myArr2 As [String]()
ReDim myArr2(myArr.Length)

' Sorts the entire Array using the default comparer.
Array.Sort(myArr)
Console.WriteLine("After sorting the entire Array using the default comparer:")
PrintIndexAndValues(myArr)

myArr2(0) = myArr(0)
j = 0
For i = 1 To myArr.Length - 1
If (myArr2(j) <> myArr(i)) Then
j = j + 1
myArr2(j) = myArr(i)
End If
Next i
ReDim Preserve myArr2(j)
Console.WriteLine("New array with no duplicate values:")
PrintIndexAndValues(myArr2)
Console.ReadLine()

End Sub 'Main

Public Shared Sub PrintIndexAndValues(ByVal myArr() As [String])

Dim i As Integer
For i = 0 To myArr.Length - 1
Console.WriteLine(" [{0}] : {1}", i, myArr(i))
Next i
Console.WriteLine()

End Sub 'PrintIndexAndValues

End Class 'SamplesArray

Andrew Steenson [MSFT]
Developer Division Sustained Engineering Team
--
This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this message are best directed to the newsgroup/thread from which they originated.

Nov 20 '05 #4

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

Similar topics

2
4306
by: D. Alvarado | last post by:
Hello, I have an array that contains numbers. Each element in the array is guaranteed to be unique. Let's say I have another variable which I know for certain is in the array, but I don't know...
3
28689
by: Filippo P. | last post by:
Hi there, I have a menu (Collection) that needs to be trimmed based on security access of the logged user. protected void AdjustMenuBasedOnUserSecurity(Items ItemsList) { foreach (Item i in...
3
972
by: WStoreyII | last post by:
i have an array of string values i have tried all day to figure a sub that will remove them but everything i have tried only leaves me with one item in the array. any ideas. Thanks in...
4
5006
by: viuxrluxvbbc | last post by:
Hi im trying to write a program that will read in numbers and display them in ascending order along with a count of how many times it repeats. i got the numerical order portion done but cant figure...
24
4343
by: RyanTaylor | last post by:
I have a final coming up later this week in my beginning Java class and my prof has decided to give us possible Javascript code we may have to write. Problem is, we didn't really cover JS and what...
6
6078
by: Niyazi | last post by:
Hi all, What is fastest way removing duplicated value from string array using vb.net? Here is what currently I am doing but the the array contains over 16000 items. And it just do it in 10 or...
2
1742
by: utahwrx | last post by:
I currently have a Javascript application that randomizes about 200 images. The problem is that the images preload, which causes the entire site to not come up until all the images are loaded. I'd...
27
2151
by: Neil | last post by:
Hello all! I wrote program with a array of pointers, and I suspect they are pointing at each other in the Do ...While loop. Something is messed up with the increment variable word. A program...
7
2798
by: =?Utf-8?B?Sm9lbCBNZXJr?= | last post by:
I have created a custom class with both value type members and reference type members. I then have another custom class which inherits from a generic list of my first class. This custom listneeds...
0
7208
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...
1
6890
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
7379
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
5464
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,...
1
4915
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...
0
4593
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...
0
3095
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1423
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 ...
1
657
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.