Search code examples
listapplescriptstartswith

Applescript and "starts with" operator


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.


Solution

  • 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