0

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. 要删除的文本项始终是最后三个
4

1 回答 1

2

尝试:

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
于 2012-10-13T00:22:48.417 回答