In one case i have to right a method to remove duplication from array of strings. i write this code Public Function RemoveDuplicates(ByVal items As String()) As String() Dim noDupsArrList As New ArrayList() For i As Integer = 0 To items.Length - 1 If Not noDupsArrList.Contains(items(i).Trim()) Then noDupsArrList.Add(items(i).Trim()) End If Next Dim uniqueItems As String() = New String(noDupsArrList.Count - 1) {} noDupsArrList.CopyTo(uniqueItems) Return uniqueItems End Function
How to remove duplicate from string array in .net
April 25, 2008 by aliraza

hi
Perfect .. its gr8 code. its solved my problem.
thank’x
best regards
feroz
Thanks!
Thank you,
It solved my problem
It’s a cool solution
Another Solution:
===============
Public Shared Function removeDuplicates(ByVal myArray As Array)
Dim i As Integer
Dim stringList As String = “”
Dim firstValue As String = “”
Dim lastValue As String = “”
Dim newArray As Array
Array.Sort(myArray)
For i = 0 To myArray.Length – 1
firstValue = CStr(myArray(i))
If UCase(firstValue) UCase(lastValue) Then
If stringList.Length = 0 Then
stringList += myArray(i)
Else
stringList += “,” & myArray(i)
End If
End If
lastValue = myArray(i)
Next i
newArray = Split(stringList, “,”)
Return newArray
End Function
Thanks,
It’s working fine.