我已经成功抓取了我要删除的文本但是当我尝试删除我指定的文本块时会抛出错误
set startText to "<target object=\"3097595957\" channel=\"./2/100\" name=\"\"/>"
set endText to "<target object=\"3097805072\" channel=\"./2/100\" name=\"\"/>"
set theFile to POSIX path of newNameFull
set theContent to read theFile as «class utf8»
set AppleScript's text item delimiters to startText
set bigChunk to text items of theContent
set AppleScript's text item delimiters to endText
repeat with subText in bigChunk
if subText contains endText then
display dialog subText
delete subText
end if
end repeat
当我显示子文本时,它是我想要删除的正确文本。但是当我尝试删除它时,我收到了这个错误:
Finder got an error: Handler can’t handle objects of this class. (-10010)
我试过研究这个错误,我很困惑。如果有人有任何建议或可以提供帮助,那将非常感激。提前致谢。
答案 0 :(得分:1)
执行以下操作:
startText
(text1)endText
(text2)之后获取文字
text1 & startText & endText & text2
set startText to "<target object=\"3097595957\" channel=\"./2/100\" name=\"\"/>"
set endText to "<target object=\"3097805072\" channel=\"./2/100\" name=\"\"/>"
set theFile to POSIX path of newNameFull
set theContent to read theFile as «class utf8»
set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to startText
set text1 to text item 1 of theContent
set AppleScript's text item delimiters to endText
set text2 to text item 2 of theContent
set AppleScript's text item delimiters to ASTID
set trimmedText to text1 & startText & endText & text2
结果在变量trimmedText
中。您可以将文本保存回磁盘。