【问题标题】:AppleScript list/containsAppleScript 列表/包含
【发布时间】:2017-03-25 14:05:52
【问题描述】:
set r to ""
set device to "IPHONE 6 PLUS SILVER 128GB-AUS"
set HighValueDevicesPass to {"IPHONE 7", "IPHONE 6", "IPAD PRO", "IPHONE 6S", "IPHONE 6 PLUS"}

if devices contains HighValueDevicesPass then
    set r to "Pass"
end if
return r

我不明白为什么这不起作用。 变量是“IPHONE 6 PLUS SILVER 128GB-AUS”,所以实际上包含列表中的“IPHONE 6 PLUS”。

如果我使用 IF 在列表中,它工作正常,但是我必须将所有不同的模型设置为变量。

如何进行部分匹配?

【问题讨论】:

    标签: if-statement applescript contain


    【解决方案1】:

    您可以检查字符串是否在列表中,但您无法检查任意列表项是否在字符串中。您必须一项一项地重复所有项目。

    set r to ""
    set device to "IPHONE 6 PLUS SILVER 128GB-AUS"
    set HighValueDevicesPass to {"IPHONE 7", "IPHONE 6", "IPAD PRO"}
    
    repeat with i from 1 to count HighValueDevicesPass
        if device contains item i of HighValueDevicesPass then
            set r to "pass"
            exit repeat
        end if
    end repeat
    
    return r
    

    我还删除了值“IPHONE 6S”和“IPHONE 6 PLUS”,因为它们已经与“IPHONE 6”字符串匹配。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-14
      • 2019-04-19
      • 1970-01-01
      相关资源
      最近更新 更多