美文网首页
AppleScript - list数组

AppleScript - list数组

作者: 不写昵称 | 来源:发表于2018-07-29 17:53 被阅读0次

    形式
    以大括号括起来,元素的类型无限制,如{“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
    

    相关文章

      网友评论

          本文标题:AppleScript - list数组

          本文链接:https://www.haomeiwen.com/subject/ibctvftx.html