VBS 数组Array 去重Unique
VBS 的数组没有去除重复值的方法
在网上搜了一圈, 找到一个可以无脑抄的方案
' returns an array of the unique items in for-each-able collection fexFunction uniqFE(fex)Dim dicTemp : Set dicTemp = CreateObject("Scripting.Dictionary")Dim xItemFor Each xItem In fexdicTemp(xItem) = 0NextuniqFE = dicTemp.Keys()End Function
示例
Dim aStudents : aStudents = Array("Arup", "John", "Mike", "John", "Lisa", "Arup")WScript.Echo Join(aStudents)Dim aUniqStudents : aUniqStudents = uniqFE(aStudents)WScript.Echo Join(aUniqStudents)
结果
Arup John Mike John Lisa ArupArup John Mike Lisa
为什么要用VBS?
VBS的好处是在windows可以直接双击执行, 代码又比传统的命令行脚本好写 (个人观点).
评论
发表评论