有没有办法检查(在applescript中)列表(或html文本块)是否有starts with
任意数量的值。
示例(检查单个值)
if {foobar starts with "<p>"} then
-- do something awesome here
end if
除了我想传递多个值来检查<p>
或<h1>
或<em>
。
提前致谢。
有没有办法检查(在applescript中)列表(或html文本块)是否有starts with
任意数量的值。
示例(检查单个值)
if {foobar starts with "<p>"} then
-- do something awesome here
end if
除了我想传递多个值来检查<p>
或<h1>
或<em>
。
提前致谢。
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
如果你想保持 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"