为Applescript文本项列表添加前缀

为Applescript文本项列表添加前缀,applescript,delimiter,Applescript,Delimiter,我有以下代码,提示用户输入逗号分隔的位置列表: 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 "") 这将产生一个包含多个项目的列表(“巴黎”、“伦敦”…) 我的意图是在列表的每

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

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 "")
这将产生一个包含多个项目的列表(“巴黎”、“伦敦”…)

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

“可编程逻辑控制器:巴黎”、“可编程逻辑控制器:伦敦”

我一直在努力,但到目前为止运气不佳。有人能给我指出正确的方向吗


谢谢。

看起来有点残忍,但效果如愿:

repeat with i from 1 to count thePlaces
    set item i of thePlaces to "plc:" & item i of thePlaces
end repeat
重复循环循环通过项目并在内容前面添加“plc:”


享受吧,迈克尔/汉堡看起来有点残忍,但工作如愿以偿:

repeat with i from 1 to count thePlaces
    set item i of thePlaces to "plc:" & item i of thePlaces
end repeat
重复循环循环通过项目并在内容前面添加“plc:”


享受吧,Michael/Hamburg

这就是使用文本项分隔符的方法,我们将每个项框起来,前面有一个唯一的值,后面有一个唯一的值,这样我们就可以区分这两个。对于如此小的列表,这真的没有用。我只是想向您展示如何做到这一点

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*)

这就是使用文本项分隔符的方法,我们将每个项都框起来,前面有一个唯一的值,后面有一个唯一的值,这样我们就可以区分这两个。对于如此小的列表,这真的没有用。我只是想向您展示一下如何做到这一点

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*)

谢谢!非常好。谢谢!非常好。很好了解更复杂的使用场景很好了解更复杂的使用场景