By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,973 Members | 1,854 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,973 IT Pros & Developers. It's quick & easy.

Removing repeated terms in an array - please help...

P: n/a
Folks,

I have an array of chars nad would like to remove any repeating
terms. Any ideas as how to do this?

Thanks,
Al.

Jan 3 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
This is data compression, if the array of char is fixed and not dynamic then
you could send it into a For Each Char in CharArray loop?

Create a StringBuilder, because strings in vb.net cannot be changed, its in
the imports system.text area?

first char = the variable that holds the 'compare to' char, compare to
nothing, its different, so append it to the stringbuilder instance

the Next char, compare to the 'compare to' char, if different, append it to
the stringbuilder instance, else next
<al*****@altavista.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
Folks,

I have an array of chars nad would like to remove any repeating
terms. Any ideas as how to do this?

Thanks,
Al.

Jan 3 '06 #2

P: n/a
Try this code. Just pass the original array to this function and it
returns an array with the duplicates removed.

Private Function RemoveDupes(ByVal myArr As Array) As Array

Dim i As Integer = 0
Dim j As Integer = 0
' Creates and initializes a new Array
Dim myArr2 As [String]()
Try
ReDim myArr2(myArr.Length)

' Sorts the entire Array using the default comparer.
Array.Sort(myArr)

myArr2(0) = CType(myArr.GetValue(0), String)
For i = 1 To myArr.Length - 1
If (myArr2(j) <> CType(myArr.GetValue(i), String)) Then
j += 1
myArr2(j) = CType(myArr.GetValue(i), String)
End If
Next i
ReDim Preserve myArr2(j)

Return myArr2
Catch ex As Exception
MsgBox(ex, MsgBoxStyle.Critical)
End Try

End Function
al*****@altavista.com wrote:
Folks,

I have an array of chars nad would like to remove any repeating
terms. Any ideas as how to do this?

Thanks,
Al.


Jan 3 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.