【发布时间】:2020-03-27 00:28:19
【问题描述】:
我正在尝试查找变量中的项目数,我尝试创建一些 while 循环来测试变量的项目是否存在,如果存在则转到下一个项目并测试它是否存在,重复此操作,直到项目不存在,然后显示当前项目编号,这应该是变量的最后一项。 这是我的代码:
set stuff to "123456789"
set x to "1"
set num to item x of stuff
if exists item x of stuff then
repeat while exists item (x + 1) of stuff
if exists (item x of stuff) then
set x to (x + 1)
else
set num to x
end if
end repeat
end if
display dialog num
目前,当我运行此代码时,我收到错误: “无法获取“123456789”的第 10 项。” 据我了解,10 是该变量的最后一项,但该信息以错误消息的形式对我没有好处。在此先感谢
【问题讨论】:
标签: applescript exists