numbers - 使用 Applescript 将字符串的结束数字分隔到变量中

标签 numbers applescript

我想知道是否可以检测随机字符串末尾的数字。例如,在这个字符串中:“localfile/random/1”我想分割这个字符串,这样一个变量将是字符串末尾的数字,第二个变量将是路径的其余部分。我无法通过谷歌搜索任何内容。

任何帮助将不胜感激。

最佳答案

如果您可以将最后一个斜杠周围的字符串分开:

set x to "localfile/random/1"
set text item delimiters to "/"
{(text items 1 thru -2 of x) as text, last text item of x}

只有当字符串始终以数字结尾时,这两种方法才有效:

on test(x)
    set c to count of x
    repeat with i from 1 to c
        if item (c - i) of x is not in items of "0123456789" then
            return {text 1 thru (c - i) of x, text (c - i + 1) thru -1 of x}
        end if
    end repeat
end test
test("localfile/random/1")

do shell script "sed -E $'s/([0-9]*)$/\\\\\\n\\\\1/' <<< " & quoted form of "localfile/random/1"
set {x, y} to paragraphs of result

关于numbers - 使用 Applescript 将字符串的结束数字分隔到变量中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15602456/

相关文章:

applescript - AppleScript:清洁字符串

php - php中的数字到单词转换(印度卢比)十进制字符串问题

javascript - 当到达 HTML 文件中的某个点时动画数字和文本

mysql - 我应该在 mysql 数据库中存储 double 还是小数?

c++ - 从第三个应用程序获取浏览器 URL

Excel for mac 隐藏功能区

macos - 有没有办法用 Applescript 触发 Finder 的 "quick look"窗口?

macos - 如何让 AppleScript SOAP 与现有的 SOAP 网络服务一起工作(例如 W3Schools 的CelsiusToFarenheit 示例)?

javascript - 与 toString(36) 相反?

javascript - 匹配不同格式的数字