AppleScript名:テキストの複数検索(ファイルから読み込んで検索) |
— Created 2017-08-09 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" property NSString : a reference to current application’s NSString property NSMutableArray : a reference to current application’s NSMutableArray property NSDate : a reference to current application’s NSDate property NSLiteralSearch : a reference to current application’s NSLiteralSearch set aFile to POSIX path of (choose file) set a1Dat to NSDate’s timeIntervalSinceReferenceDate() set aStr to NSString’s stringWithContentsOfFile:aFile encoding:(current application’s NSUTF8StringEncoding) |error|:(missing value) set aRes to searchWordRanges(aStr, "子供") of me as list –> {{location:1159, length:2}, {location:1242, length:2}, {location:1261, length:2}, ….. set b1Dat to NSDate’s timeIntervalSinceReferenceDate() set c1Dat to b1Dat – a1Dat on searchWordRanges(aTargText as string, aSearchStr as string) set aStr to NSString’s stringWithString:aTargText set bStr to NSString’s stringWithString:aSearchStr set hitArray to NSMutableArray’s alloc()’s init() set cNum to (aStr’s |length|()) as integer set aRange to current application’s NSMakeRange(0, cNum) repeat set detectedRange to aStr’s rangeOfString:bStr options:(NSLiteralSearch) range:aRange if detectedRange’s location is equal to current application’s NSNotFound then exit repeat hitArray’s addObject:detectedRange set aNum to (detectedRange’s location) as integer set bNum to (detectedRange’s |length|) as integer set aRange to current application’s NSMakeRange(aNum + bNum, cNum – (aNum + bNum)) end repeat return hitArray end searchWordRanges |
More from my site
(Visited 30 times, 1 visits today)