Applescript and "starts with" operator

VicePrez picture VicePrez · May 8, 2011 · Viewed 7.2k times · Source

Is there a way to check (in applescript) if a list (or block of html text) starts with any number of values.

Example (checking for a single value)

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

except i would like to pass multiple values to check <p> or <h1> or <em>.

Thanks in advance.

Answer

Lri picture Lri · May 8, 2011
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