我有以下代码,它会提示用户输入以逗号分隔的地方列表:
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”。
一直在尝试但到目前为止没有运气。有人能指出我正确的方向吗?
感谢。
答案 0 :(得分:3)
看起来有点残酷,但希望如下:
repeat with i from 1 to count thePlaces
set item i of thePlaces to "plc:" & item i of thePlaces
end repeat
重复循环遍历项目并添加" plc:"在内容面前...
享受,迈克尔/汉堡
答案 1 :(得分:1)
这是你可以用文本项分隔符来实现的,我们选中每个项目,前面有一个唯一的值,最后一个,所以我们可以区分这两个。真的,没有用这么小的名单。我只是想告诉你如何做到这一点。
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*)