AppleScript名:指定要素のみを削除(predicateでfilter) v3 |
— Created 2017-11-03 by Takaaki Naganoya — Modified 2017-11-05 by Shane Stanley use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "AppKit" property NSPredicate : a reference to current application’s NSPredicate property NSArray : a reference to current application’s NSArray set aList to {"Apple", "Lemon", "Aple", "Lum", "Apple"} set aTarg to "Apple" –string set rList to removeElementsFrom1DArray(aList, aTarg) of me –> {"Lemon", "Aple", "Lum"} set bList to {1, 2, 3, 1, 5} set bTarg to 1 –number set rList to removeElementsFrom1DArray(bList, bTarg) of me –> {2, 3, 5} set cList to {1, 2, 3, 1, 5} set cTarg to {1, 2, 3} –list of number set rList to removeElementsFrom1DArray(cList, cTarg) of me –> {5} set dList to {"Apple", "Lemon", "Aple", "Lum", "Apple"} set dTarg to {"Apple", "Lemon"} –list of string set rList to removeElementsFrom1DArray(dList, dTarg) of me –> {"Aple", "Lum"} on removeElementsFrom1DArray(aList as list, aTarg as {number, string, list}) set anArray to NSArray’s arrayWithArray:aList set aClass to class of aTarg if aClass = list then set thePred to NSPredicate’s predicateWithFormat_("NOT SELF IN %@", aTarg) else set thePred to NSPredicate’s predicateWithFormat_("SELF != %@", aTarg) end if set bList to (anArray’s filteredArrayUsingPredicate:thePred) as list return bList end removeElementsFrom1DArray |
More from my site
(Visited 29 times, 1 visits today)