我想逐段阅读文本文件,并且由于文件的内容是德语,因此文件包含特殊字符,并且我知道我必须使用utf8类才能将字符正确读取到脚本中。
如果使用建议的命令,我会遇到问题
set txt to paragraphs of (read foo for (get eof foo)) as «class utf8»
Run Code Online (Sandbox Code Playgroud)
我得到错误
error "Can’t make {\"\tDate:\t10. J?§nner 2006 20:53\", \"\tTags:\tHase, Muffin, Paul\", \"\tLocation:\tM?ºhlgasse, Wiener Neudorf, Lower Austria, Austria\", \"\tWeather:\t-7¬? Clear\", \......
Run Code Online (Sandbox Code Playgroud)
如果我在没有«class utf8»的情况下读取文件,则不会发生错误。
我使用以下代码:
set theFile to readFile("/Users/Muffin/Documents/DayOne-Export/DayOne.md")
-- set Shows to read theFile using delimiter return
repeat with nextLine in theFile
<text processing>
end repeat
on readFile(unixPath)
-- prepare text file to read
set foo to (open for access (POSIX file unixPath))
set txt …Run Code Online (Sandbox Code Playgroud)