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

ClouDNS .asia免费域名 托管到CloudFlare开CDN白嫖Websocket WS通道翻墙 / desec.io

无服务器 自建短链服务 Url-Shorten-Worker 完整的部署教程