如何检查字符串(元素)是否包含在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}}人
人已捐赠
教程

自己写的一个固话自动拨号程序,分享出来

2021-7-8 14:47:41

教程

神器遇到神器,使用AutoHotkey调用everything.dll进行搜索的简单案例

2021-7-14 9:10:19

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

    666666

  2. wingleaf

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

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