Kev*_*vin 5 applescript if-statement contain
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
Run Code Online (Sandbox Code Playgroud)
我不明白为什么这不起作用。该变量是“IPHONE 6 PLUS SILVER 128GB-AUS”,因此实际上包含列表中的“IPHONE 6 PLUS”。
如果我使用 IF is on the list,它工作正常,但随后我必须将所有不同的模型设置为变量。
如何进行部分匹配?
您可以检查字符串是否在列表中,但无法检查任意列表项是否在字符串中。你必须一一重复所有的项目。
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
Run Code Online (Sandbox Code Playgroud)
我还删除了值“IPHONE 6S”和“IPHONE 6 PLUS”,因为它们已经与“IPHONE 6”字符串匹配。
| 归档时间: |
|
| 查看次数: |
6801 次 |
| 最近记录: |