AppleScript名:ASOCでテキストを行ごとにparseしてNSArrayに |
— Created 2015-07-02 17:32:59 +0900 by Takaaki Naganoya — 2015 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set aText to "ABCDE 01234 あいうえお かきくけこ さしすせそ たちつてと なにぬねの" set aArray to parseParagraphs(aText) of me set aRes to countArrayItems(aArray) of me –> 7 –最初のアイテム set bRes to retFirstObject(aArray) of me –> (NSString) "ABCDE" –最後のアイテム set cRes to retLastObject(aArray) of me –> (NSString) "なにぬねの" –指定アイテム目のアイテム set dRes to retNthObject(aArray, 2) of me –> (NSString) "01234" –テキストを改行でParseしてArrayに on parseParagraphs(a) set aStr to current application’s NSString’s stringWithString:a set retStr to current application’s NSString’s stringWithString:(string id 10) set aRes to (aStr’s componentsSeparatedByString:retStr) –parse strings by return return aRes end parseParagraphs –与えられた配列の要素数を返す on countArrayItems(aArray) set aRes to aArray’s |count|() return aRes end countArrayItems –与えられた配列の最初の要素を返す on retFirstObject(aArray) set a to aArray’s firstObject() return a end retFirstObject –与えられた配列の最後の要素を返す on retLastObject(aArray) set a to aArray’s lastObject() return a end retLastObject –与えられた配列の指定アイテム目の要素を返す on retNthObject(aArray, nTh) if nTh ≤ 0 then return false set aIndex to current application’s NSNumber’s numberWithInt:((nTh – 1) as integer) set aRes to aArray’s objectAtIndex:aIndex return aRes end retNthObject |
More from my site
(Visited 30 times, 1 visits today)