如何使用 VBscript 从值列表中获取唯一值? [英] How to get unique values from a list of values using VBscript?
本文介绍了如何使用 VBscript 从值列表中获取唯一值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设一个 Excel 工作表有一个名为 Student Names 的列,并且该列有重复的值.说,
Suppose an Excel sheet has a column named Student Names and the column has duplicate values. Say,
Student
=======
Arup
John
Mike
John
Lisa
Arup
使用 VBScript,我如何获得如下唯一值?
Using VBScript, how can I get unique values as below?
Arup
John
Lisa
Mike
推荐答案
用于获取唯一项的 VBScript 工具是一个字典:将所有项作为键添加到字典中,dictionary.Keys() 将返回 -根据定义 - 唯一键.在代码中:
The VBScript tool for getting unique items is a dictionary: add all the items as keys to a dictionary and dictionary.Keys() will return an array of the - per definitionem - unique keys. In code:
Dim aStudents : aStudents = Array("Arup", "John", "Mike", "John", "Lisa", "Arup")
WScript.Echo Join(aStudents)
Dim aUniqStudents : aUniqStudents = uniqFE(aStudents)
WScript.Echo Join(aUniqStudents)
' returns an array of the unique items in for-each-able collection fex
Function uniqFE(fex)
Dim dicTemp : Set dicTemp = CreateObject("Scripting.Dictionary")
Dim xItem
For Each xItem In fex
dicTemp(xItem) = 0
Next
uniqFE = dicTemp.Keys()
End Function
输出:
Arup John Mike John Lisa Arup
Arup John Mike Lisa
这篇关于如何使用 VBscript 从值列表中获取唯一值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文