如何检查字符串是否包含在AutoHotKey中的数组中

时间:2015-11-08 07:20:47

标签: arrays string autohotkey contains

我有以下代码:

ignored := [ "Rainmeter.exe", "Nimi Places.exe", "mumble.exe" ]

a := ignored.HasKey("mumble.exe")
MsgBox,,, %a%

即使字符串明确存在于数组中,它也会返回0

如何测试数组中是否存在字符串值?

PS:我也试过if var in,结果相同。

1 个答案:

答案 0 :(得分:5)

你不能,只使用一个命令。自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()是有意义的。

相关问题