vbscript 从阵列中删除重复项

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vbscript 从阵列中删除重复项相关的知识,希望对你有一定的参考价值。

Function RemoveDuplicates(InputArray as Variant, OutputArray as Variant) As Boolean
'Description:	Removes duplicate values from a single-dimensional array
'				and writes the result to another array
'Dependencies:	Array Support module
'				ZeroToOneBasedArray

Dim dic         As Object
Dim key         As Variant
Dim tempArr()   As Variant

' 	Set the default result
	RemoveDuplicates = False

' 	Ensure InputArray is an array.
	If IsArray(InputArray) = False Then Exit Function

' 	Ensure InputArray is not empty.
	If IsArrayEmpty(InputArray) Then Exit Function

' 	Ensure we have a single dimensional array
	If NumberOfArrayDimensions(arr:=InputArray) <> 1 Then Exit Function


    Set dic = CreateObject("Scripting.Dictionary")
    For Each key In InputArray
        dic(key) = 0
    Next

'	Convert to 1 based array, if needed (NB: dic.keys is always zero-based array)
	If LBound(InputArray)=1 then
		tempArr = ZeroToOneBasedArray(dic.keys)
	Else
		tempArr = dic.keys
	End If
    
    OutputArray = tempArr
	RemoveDuplicates = True
                
End Function

以上是关于vbscript 从阵列中删除重复项的主要内容,如果未能解决你的问题,请参考以下文章

JavaScript 从阵列2中删除重复值

JavaScript 从阵列中删除重复值

从阵列中删除重复点

VBScript通过重新编号从字幕文件中删除重复的数字

如何使用 ShellExecute 从 VBScript 将参数传递给批处理文件 [重复]

从列表中删除重复项?