如何检查字符串(元素)是否包含在AutoHotKey中的数组中(How to check if string is contained in an array in AutoHotKey)

判定数组元素是否在数组中autohotkey并没有提供现成的方法,我这里给大家提供一下解决方案。

分两种情况:

一、如果是关联数组

;关联数组的值是否存在的判定
da := { "c":0, "b":0, "a":0 }
if % da.HasKey("a")
    msgbox,有
Else
    MsgBox,没有

二、如果是简单数组要麻烦一点,需要自己写一个函数实现

;简单数组的值是否存在的判定
da := ["c","b","a"]
if % HasValue(da,"a")
    msgbox,有
Else
    MsgBox,没有
    
Return
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
}

如何检查字符串(元素)是否包含在AutoHotKey中的数组中(How to check if string is contained in an array in AutoHotKey)

给TA捐赠
共{{data.count}}人
人已捐赠
其他

一键恢复QQ浏览器的收藏夹并启动QQ浏览器.bat

2021-7-13 12:19:05

其他案例

隐藏桌面图标

2021-7-14 8:29:10

4 条回复 A文章作者 M管理员
  1. user15439

    666666

  2. wingleaf

    var=”a” if var in “c”,”b”,”a” msgbox,有 Else MsgBox,没有

个人中心
购物车
优惠劵
有新私信 私信列表
搜索