我有以下工作示例 AppleScript 片段:
set str to "This is a string"
set outlist to {}
repeat with wrd in words of str
if wrd contains "is" then set end of outlist to wrd
end repeat
我知道 AppleScript 中的 who 子句通常可用于替换诸如此类的重复循环以显着提高性能。然而,对于文本元素列表,如单词、字符和段落,我无法找到一种方法来完成这项工作。
我努力了:
set outlist to words of str whose text contains "is"
这失败了:
error "Can’t get {\"This\", \"is\", \"a\", \"string\"} whose text contains \"is\"." number -1728
,大概是因为“文本”不是文本类的属性。查看text class 的 AppleScript Reference,我看到“引用的表单”是 text 类的属性,所以我有一半的预期是这样的:
set outlist to words of str whose quoted form contains "is"
但这也失败了,有:
error "Can’t get {\"This\", \"is\", \"a\", \"string\"} whose quoted form contains \"is\"." number -1728
有没有办法用 AppleScript 中的 who 子句替换这样的重复循环?