AppleScript - list数组

形式
以大括号括起来,元素的类型无限制,如{“hello”,123,"world"}

设置

set arr1 to {"hello", 123, "word", "!"} --元素类型无限制
set arr2 to {"good", "morning", "!"}

合并

set arr3 to arr1 & arr2  -- 合并

获取元素个数

get the length of arr3
get the count of arr3

获取值
注:list的序号从1开始

get item 2 of arr3  -- 获取第二个元素,即123
get 2nd item of arr3
get the second item of arr3 --该种方式只能用到tenth 
get item -1 of arr3 -- -1表示最后一个,-2表示倒数第2个。。。
get items 2 through 5 of arr3 -- 获取第2到第5个元素

添加元素

set the end of arr3 to "new"  --在最后添加一个元素“new”

未解决: 在指定的位置插入值 ???

更改值

set arr to {"张三", "李四", "王五", "谢六"}
--set the item 2 of arr to "胜七"
--set the 2nd item of arr to "胜七"
--set the second item of arr to "胜七"
get arr

获取逆序后的数组

get reverse of arr3

随机获取数组的一个元素

get some item of arr3

类型转换

get arr3 as string --将数组的元素凭借成一个字符串

字符串切割成数组
见-字符串

按指定的符号将数组拼接成字符串

set defaultDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to "-"
set arr3Str to arr3 as string
set AppleScript's text item delimiters to defaultDelimiters
get arr3Str
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容