为 Applescript 文本项列表添加前缀

Prefixing an Applescript text items list

我有以下代码,提示用户输入逗号分隔的位置列表:

set AppleScript's text item delimiters to {","}

set thePlaces to the text items of the text returned of (display dialog "Insert referenced places separated by commas" default answer "")

这将产生一个包含多个项目("Paris"、"London"、...)的列表。

我的意图是在此列表的每个项目前加上一个字符串(例如 "plc:"。 最后,我希望列表由以下项目组成:

"plc:Paris", "plc:London".

一直在尝试,但到目前为止没有成功。谁能指出我正确的方向?

谢谢。

看起来有点野蛮,但如愿以偿:

repeat with i from 1 to count thePlaces
    set item i of thePlaces to "plc:" & item i of thePlaces
end repeat

repeat循环循环遍历item,在内容前面加上"plc:"...

享受吧,迈克尔/汉堡

这就是使用文本项定界符的方法,我们将每个项目装箱,前面有一个唯一值,结尾有一个值,这样我们就可以区分两者。真的,这么小的列表对这个没有用。我只是想告诉你怎么做。

set astid to text item delimiters
set the places to "Paris,London,Rome"
set text item delimiters to ","
set lstItms to text items of the places
-- we "box" the text items, so that every one is prepended with a return, and has a linefeed appended to it.
set text item delimiters to return & linefeed
set places to lstItms as text
set text item delimiters to astid
set places to linefeed & places & return
-- our list is in shape, time to do the actual replacement.
set text item delimiters to linefeed
set lstItms to text items of places
set text item delimiters to "plc:"
set places to lstItms as text
set text item delimiters to return
set lstItms to text items of places
set text item delimiters to astid
log item 1 of lstItms
(*plc:Paris*)