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

标签 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.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/

相关文章:

java - 从java中的字符串中获取整数

php - 将二维数组转换为多维

c - 使用 getchar() 和 putchar() 将 int 与字符串交换

c++ - 如何读取一个文件,反转文本的一部分并将反转的部分写入 C++ 上的另一个文件?

windows - 使用 AutoHotKey (AHK) 创建类似 Vim 的功能

Autohotkey::= 和 = 赋值运算符有什么区别

带和不带花括号的 autohotkey if 语句

c++ - 如何在运行时使用 array<int,10> 或 array<int,4> ?

python - 如何在 Cython 中创建固定长度、可变的 Python 对象数组?

c - 输入字符串时程序不打印字符