473,626 Members | 3,340 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 981
* "WStoreyII" <pa**********@s bcglobal.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.Collecti ons

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.Le ngth)

' Sorts the entire Array using the default comparer.
Array.Sort(myAr r)
Console.WriteLi ne("After sorting the entire Array using the default comparer:")
PrintIndexAndVa lues(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.WriteLi ne("New array with no duplicate values:")
PrintIndexAndVa lues(myArr2)
Console.ReadLin e()

End Sub 'Main

Public Shared Sub PrintIndexAndVa lues(ByVal myArr() As [String])

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

End Sub 'PrintIndexAndV alues

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
4314
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 the position. What's the quickest way for removing that element? I know I could just use a foreach, but I'm sure one of the experts out there has a better way. Thanks, - Dave
3
28698
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 ItemsList) {
3
1379
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 advance WStoreyII
4
5012
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 out the other part. i keep on getting a wrong number please help #include <iostream> using namespace std; int main() {
24
4370
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 we covered was within the last week of the class and all self taught. Our prof gave us an example of a Java method used to remove elements from an array: public void searchProcess() { int outIt=0;
7
1746
by: Adam Honek | last post by:
Is there a direct way to remove one entry from a one dimensional array? I keep looking but either my eyes are funny or it isn't there. Must we really create a temp array and copy all but 1 of the entries over to delete one entry? All I want to do is remove an entry at a specified index and then have the ubound(array) go down -1.
6
6099
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 more minutes. 'REMOVE DUBLICATED VALUE FROM ARRAY +++++++++++++++++ Dim col As New Scripting.Dictionary Dim ii As Integer = 0
2
1763
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 like to find a Javascript application that can load images as they are randomly chosen. In addition, I'm trying to figure out how to not display the same image more than once; or at least until after the 200 have been displayed, then create a new...
27
2166
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 clip of what I'm talking about. #include <stdio.h> #include <string.h>
7
2825
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 to support cloning: Public Class RefClass Public tcp As TcpClient Public name As String End Class Public Class RefClassList Inherits List(Of RefClass) Implements ICloneable
0
8266
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8199
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
8638
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...
1
8365
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8505
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
5574
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();...
0
4092
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1811
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1511
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.