AppleScript名:文字列から開始文字列と終了文字列に囲まれた内容を削除 |
— Created 2016-12-12 by Shane Stanley — Modified 2016-12-14 by edama2 use AppleScript version "2.4" use scripting additions use framework "Foundation" –http://piyocast.com/as/archives/4358 set aStr to "thru (throughも可)" set aRes to (trimStrFromTo(aStr, "(", ")") of me) –> "thru " set bStr to "thru " set bRes to (trimStrFromTo(bStr, "(", ")") of me) –> "thru " 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) — terminate check, return the result (aDict) to caller set {theResult, theKey} to theScanner’s scanUpToString:fromStr intoString:(reference) — skip over separator 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 "" –>追加 — skip over separator 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 14 times, 1 visits today)