我有以下代码:
ignored := [ "Rainmeter.exe", "Nimi Places.exe", "mumble.exe" ]
a := ignored.HasKey("mumble.exe")
MsgBox,,, %a%
即使字符串明显存在于数组中,它也会返回 0
。
如何测试数组中是否存在字符串值?
PS:我还尝试了 if var in
,它给出了相同的结果。
最佳答案
你不能,只使用一个命令。自 1.1.22.3 起,此类功能尚未在 AHK_L 中实现。
您必须定义自己的函数
hasValue(haystack, needle) {
if(!isObject(haystack))
return false
if(haystack.Length()==0)
return false
for k,v in haystack
if(v==needle)
return true
return false
}
或者使用一些奇特的解决方法:
ignored := { "Rainmeter.exe":0, "Nimi Places.exe":0, "mumble.exe":0 }
msgbox, % ignored.HasKey("mumble.exe")
这将创建一个关联数组并将您的值作为键(此处的值设置为 0),因此 .HasKey()
使用起来很有意义。
关于arrays - 如何检查 AutoHotKey 中的数组中是否包含字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33591667/