AppleScript名:1D List内の文字、数値検索 |
use AppleScript version "2.4" use scripting additions use framework "Foundation" set aList to {5, 2, 3, 4, 1} set aRes to findItemNumFrom1DArray(aList, 5, false) of me –> 1 set aRes to findItemNumFrom1DArray(aList, 5, true) of me –> 5 set aList to {"1", "2", "3", "4", "5"} set aRes to findItemNumFrom1DArray(aList, "3", false) of me –> 3 on findItemNumFrom1DArray(aList as list, targItem as list of string or string, sortSW as boolean) set anArray to current application’s NSArray’s arrayWithArray:aList if sortSW = true then set anArray to anArray’s sortedArrayUsingSelector:"compare:" end if set aInd to anArray’s indexOfObject:targItem if (aInd = current application’s NSNotFound) or (aInd > 9.999999999E+9) then return false else return (aInd + 1) as integer end if end findItemNumFrom1DArray |
More from my site
(Visited 18 times, 1 visits today)