指定の1D List(Array)でゼロが入っていたら、末尾のゼロの前の要素で埋めるAppleScriptです。
{"1", "2", "3", "4", "0", "0"}
のようなリストがあった場合に、
{"1", "2", "3", "4", "4", "4"}
のような処理を行います。
AppleScript名:指定の1D Listでゼロが入っていたら末尾のゼロの前の要素で埋める |
— Created 2019-01-03 by Takaaki Naganoya — 2019 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set aList to {"11111", "22222", "33333", "44444", "0", "0"} set abList to fillByLastItemIfZero(aList) –> {"11111", "22222", "33333", "44444", "44444", "44444"} –指定の1D Listでゼロが入っていたらゼロの前の要素で埋める on fillByLastItemIfZero(aList as list) set aLen to length of aList set bList to {} set prevDat to -1 set aFirst to (contents of first item of aList) as string if aFirst = "0" then error "First Item is 0 in a list" repeat with i in aList set aTmp to i as string if aTmp = "0" then copy prevDat to aTmp else copy aTmp to prevDat end if set the end of bList to aTmp end repeat return bList end fillByLastItemIfZero |
More from my site
(Visited 27 times, 1 visits today)