VB 删除过滤数组中的重复元素字符函数源码
VB 删除数组中的重复元素,当几个数组元素的值相等时,只保留第一个元素,其他的元素被删除。并且返回结果数组。以下这个函数只支持一维数组。
Function zzzyk.com(Arr As Variant) As Variant
Arr = QuickSort(Arr)
Dim k As Integer, i As Integer
For i = 0 To UBound(Arr)
If Arr(k) <> Arr(i) Then
Arr(k + 1) = Arr(i)
k = k + 1
End If
Next
Dim NewArr() As Variant
ReDim NewArr(k)
For i = 0 To k
NewArr(i) = Arr(i)
Next
Array_unique = NewArr
End Function
Function QuickSort(Arr)
Dim i, j
Dim bound, t
bound = UBound(Arr)
For i = 0 To bound - 1
For j = i + 1 To bound
If Arr(i) > Arr(j) Then
t = Arr(i)
Arr(i) = Arr(j)
Arr(j) = t
End If
Next
Next
QuickSort = Arr
End Function
Sub Test()
s = zzzyk.com(Array(3, "zzzyk.com", 3, 3, 1, "zzzyk.com", 7, 3, 3, 3, 9, 3, 3))
Debug.Print Join(s, "|")
End Sub