将 AppleScript 列表转换为字符串 [英] Convert AppleScript List into String

查看:43
本文介绍了将 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

推荐答案

有一个简短的方法,叫做文本项分隔符

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 列表转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆