3

starts withリスト(またはHTMLテキストのブロック)に任意の数の値があるかどうかを(applescriptで)チェックする方法はありますか?

例(単一の値をチェックする)

if {foobar starts with "<p>"} then
    -- do something awesome here
end if

<p>チェックまたは<h1>またはに複数の値を渡したい場合を除きます<em>

前もって感謝します。

4

2 に答える 2

8
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
于 2011-05-08T20:42:51.133 に答える
5

上記の例よりも長くなりますが、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"
于 2011-05-11T07:08:21.510 に答える