VBS 数组Array 去重Unique

VBS 的数组没有去除重复值的方法

在网上搜了一圈, 找到一个可以无脑抄的方案

感谢 https://stackoverflow.com/questions/13743165/how-to-get-unique-values-from-a-list-of-values-using-vbscript#13744080

' 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


示例

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 Arup
Arup John Mike Lisa

为什么要用VBS?

VBS的好处是在windows可以直接双击执行, 代码又比传统的命令行脚本好写 (个人观点).

评论

The Hot3 in Last 30 Days

RackNerd VPS搭Hysteria2 HY2梯子 年付 $10.98 1G端口 3T流量 17G存储 1GB内存

强行重装 233boy的sing-box脚本 取消脚本报错退出的逻辑