AppleScript名:指定のテキストからHTMLタグを除去(NSScanner) |
— Created 2016-12-12 by Shane Stanley — Modified 2016-12-14 by edama2 — Modified 2017-11-28 by Takaaki Naganoya use AppleScript version "2.4" use scripting additions use framework "Foundation" –set aStr to read (choose file) set aStr to "<a>repeat</a>~end repeat<BR>" set aRes to (trimStrFromTo(aStr, "<", ">") of me) –> "repeat~end repeat" on trimStrFromTo(aParamStr, fromStr, toStr) set theScanner to current application’s NSScanner’s scannerWithString:aParamStr set anArray to current application’s NSMutableArray’s array() repeat until (theScanner’s isAtEnd as boolean) set {theResult, theKey} to theScanner’s scanUpToString:fromStr intoString:(reference) theScanner’s scanString:fromStr intoString:(missing value) set {theResult, theValue} to theScanner’s scanUpToString:toStr intoString:(reference) if theValue is missing value then set theValue to "" theScanner’s scanString:toStr intoString:(missing value) anArray’s addObject:theValue end repeat if anArray’s |count|() = 0 then return aParamStr copy aParamStr to curStr repeat with i in (anArray as list) set curStr to repChar(curStr, fromStr & i & toStr, "") of me end repeat return curStr end trimStrFromTo on repChar(aStr, targStr, repStr) set aString to current application’s NSString’s stringWithString:aStr set bString to aString’s stringByReplacingOccurrencesOfString:targStr withString:repStr set cString to bString as string return cString end repChar |
More from my site
(Visited 12 times, 1 visits today)