【问题标题】:Delimiters - How to remove last 3 text items分隔符 - 如何删除最后 3 个文本项
【发布时间】:2012-10-13 00:19:36
【问题描述】:

AppleScript 分隔符

如何删除最后 3 个文本项?

我的清单如下:

{"Water", "Management", "in", "Ancient", "Greek", "Cities", "Jun", "1993", "pdf"}

我想删除最后 3 个文本项(例如:"Jun, "1993", and "pdf")。

到目前为止,这是我的脚本:

set AppleScript's text item delimiters to ["USA."]
set stringToUse to "04.Oxford.University.Press.USA.Water.Mngt.in.Ancient.Greek.Cities.Jun.1993.pdf" as string
set stringUSA to last text item of stringToUse
set AppleScript's text item delimiters to ["."]
set pathNames to text item of stringUSA
return pathNames

作为一般规则,重要的是:

  1. 列表中文本项的数量可以是变量
  2. 要删除的文本项总是最后三个

【问题讨论】:

    标签: text applescript delimiter


    【解决方案1】:

    试试:

    set AppleScript's text item delimiters to "USA."
    set stringToUse to "04.Oxford.University.Press.USA.Water.Mngt.in.Ancient.Greek.Cities.Jun.1993.pdf" as string
    set stringUSA to last text item of stringToUse
    set AppleScript's text item delimiters to "."
    set pathNames to text items 1 thru -4 of stringUSA
    set AppleScript's text item delimiters to {""}
    return pathNames
    

    【讨论】:

      猜你喜欢
      • 2013-01-17
      • 1970-01-01
      • 1970-01-01
      • 2018-03-10
      • 2017-03-26
      • 2016-02-07
      • 2018-02-23
      • 2014-09-08
      • 2017-08-19
      相关资源
      最近更新 更多