我想實作這個Objective-C的例子,以便在AppleScript中使用,但我不知道如何做到這一點。
NSTextCheckingResult *match = [regex firstMatchInString:string
選項:0
range:NSMakeRange(0, [string length])】。]
if (match) {
NSRange matchRange = [匹配范圍];
NSRange firstHalfRange = [match rangeAtIndex:1] 。
NSRange secondHalfRange = [match rangeAtIndex:2]。
}
這是我目前得到的結果,我不知道該如何繼續下去
set theString to "hello world"
設定theString2為"w "。
設定firstMatch為(regex的firstMatchInString:theString options:0 range:{location:0, |length|:(count theString)}) as list -- 我是否需要脅迫到串列?
-- 下面顯然是錯誤的
如果firstMatch不是丟失的值,那么
set matchRange = current application's NSRange的范圍。
結束 如果
uj5u.com熱心網友回復:
在這種情況下只存在一個范圍(index=0)。所以,不要請求在索引> 0處的范圍
。使用AppleScript版本"2.4" -- Yosemite或更高版本
使用框架 "Foundation" -- Yosemite或更高版本
使用腳本添加
設定searchString為"hello world"/span>
設定regexString為"w "。
設定anNSString為當前應用的NSString's stringWithString:searchString
設定stringLength為一個NSString's |length|()
設定Regex為當前應用程式的s NSRegularExpression的regularExpressionWithPattern:regexString options:0 |error|:(missing values)
設定匹配到Regex的s firstMatchInString:anNSString options:0 range:{0, stringLength}。
if 匹配不是缺失值,那么
設定matchRange為match的numberOfRanges()
--> 1,所以只存在一個范圍,索引=0
設定matchRange為match的s rangeAtIndex:0。
結束 if
設定firstMatchString為searchString的文本((matchRange's location) 1)到((matchRange's location) (matchRange's |length|))。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/323506.html
標籤:
上一篇:將資料傳遞給組件時出現未定義錯誤
下一篇:帖子中使用的標簽被用戶評論的次數
