将AppleScript列表转换为字符串

将AppleScript列表转换为字符串

本文介绍了将AppleScript列表转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一种简便的方法可以将AppleScript列表转换为分隔每个项目的字符串.我可以以一种我想要的更长的方式来实现这一目标,所以我想知道是否有一种简单的方法可以实现这一目标.基本上,我想获取一个列表,例如{1,2,3}并将其转换为字符串"1, 2, 3".我可以做类似下面的操作,但是结果字符串后面会出现逗号:

I was wondering if there is a short way to convert an AppleScript list into a string separating each item. I can achieve this in a way which is more lengthy that I would like, so I wondered if there is a simple way to achieve this. Basically, I would like to take a list such as {1,2,3} and convert it in to a string "1, 2, 3". I can do something like below, but that results in a comma following the resulting string:

set myList to {"1.0", "1.1", "1.2"}
set Final to ""
if (get count of myList) > 1 then
    repeat with theItem in myList
        set Final to Final & theItem & ", "
    end repeat
end if

推荐答案

有一个简短的方法,称为text item delimiters

There is a short way, it's called text item delimiters

set myList to {"1.0", "1.1", "1.2"}
set saveTID to text item delimiters
set text item delimiters to ", "
set Final to myList as text
set text item delimiters to saveTID

这篇关于将AppleScript列表转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 02:20