AppleScript名:単語ベースの文字列間のdiffをとる(NSMutableSet) |
— Created 2016-02-21 by Takaaki Naganoya — 2016 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set str1 to current application’s NSString’s stringWithString:"My cat sometimes likes to eat fish." set str2 to current application’s NSString’s stringWithString:"My cat always likes to drink fresh water, and eat fish." set set1 to current application’s NSMutableSet’s setWithArray:(str1’s componentsSeparatedByString:" ") set set2 to current application’s NSMutableSet’s setWithArray:(str2’s componentsSeparatedByString:" ") set2’s minusSet:set1 set anArray to (set2’s allObjects()) as list –> {"always", "water,", "and", "drink", "fresh"}–str1になくてstr2にあるもの set set3 to current application’s NSMutableSet’s setWithArray:(str1’s componentsSeparatedByString:" ") set set4 to current application’s NSMutableSet’s setWithArray:(str2’s componentsSeparatedByString:" ") set4’s unionSet:set3 set anArray to (set4’s allObjects()) as list –> {"to", "water,", "My", "cat", "likes", "fish.", "drink", "eat", "and", "fresh", "always", "sometimes"}–合成してユニーク化 set set5 to current application’s NSMutableSet’s setWithArray:(str1’s componentsSeparatedByString:" ") set set6 to current application’s NSMutableSet’s setWithArray:(str2’s componentsSeparatedByString:" ") set6’s intersectSet:set5 set anArray to (set6’s allObjects()) as list –> {"eat", "My", "cat", "likes", "to", "fish."}–共通項 set set7 to current application’s NSMutableSet’s setWithArray:(str1’s componentsSeparatedByString:" ") set set8 to current application’s NSMutableSet’s setWithArray:(str2’s componentsSeparatedByString:" ") set8’s setSet:set7 set anArray to (set8’s allObjects()) as list –> {"eat", "sometimes", "My", "cat", "likes", "to", "fish."}–置き換え。NSMutableSet配列の要素を全て削除し、指定したNSSet配列のオブジェクトを追加する |
More from my site
(Visited 40 times, 1 visits today)