≡ Menu




How to remove duplicate from string array in .net

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
{ 0 comments… add one }

Leave a Comment