有没有办法检查(在AppleScript中)列表(或html文本块)starts with
是否有任意数量的值。
示例(检查单个值)
if {foobar starts with "<p>"} then
-- do something awesome here
end if
除了我想传递多个值以检查<p>
或<h1>
或<em>
。
提前致谢。
答案 0 :(得分:6)
on startswith(txt, l)
repeat with v in l
if txt starts with v then return true
end repeat
false
end startswith
startswith("abc", {"a", "d", "e"}) -- true
答案 1 :(得分:4)
如果您希望保持AppleScript的“英式”风格,虽然比上面的示例更长,但您可以这样做:
if {foobar starts with "hello" or foobar starts with "goodbye"} then
一个完整的例子是:
set foobar to "hello dude"
if {foobar starts with "hello" or foobar starts with "goodbye"} then
display dialog "found"
end if
即使你改变了也是如此:
set foobar to "hello dude"
为:
set foobar to "goodbye dude"