Applescript 和“开头为”操作员

发布于 2024-11-05 09:35:45 字数 310 浏览 5 评论 0原文

有没有办法检查(在applescript中)列表(或html文本块)是否以任意数量的值开头。

示例(检查单个值),

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

但我想传递多个值来检查

< /代码>。

提前致谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

回眸一遍 2024-11-12 09:35:45
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
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
江挽川 2024-11-12 09:35:45

如果您想保持 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"

If you want to stay within the 'English' style of AppleScript, although longer than the example above, you can just do this:

if {foobar starts with "hello" or foobar starts with "goodbye"} then

A full example would be:

set foobar to "hello dude"
if {foobar starts with "hello" or foobar starts with "goodbye"} then
    display dialog "found"
end if

That will be true even if you change:

set foobar to "hello dude"

to:

set foobar to "goodbye dude"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文