我想逐段从文本文件中读取,因为文件的内容是德语,所以文件包含特殊字符,我理解我必须使用utf8类来正确地将字符读入脚本中。
如果使用建议的命令,我将面临这个问题。
set txt to paragraphs of (read foo for (get eof foo)) as «class utf8»我知道错误了
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\", \......如果我在没有utf8 8类的情况下读取文件,则不会发生错误。
我使用以下代码:
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 to paragraphs of (read foo for (get eof foo)) as «class utf8»
-- set txt to paragraphs of (read foo) as «class utf8»
close access foo
return txt
end readFile文本文件如下所示:
Date: 10. Jänner 2006 20:53<br>
Tags: Hase, Muffin, Paul<br>
Location: Mühlgasse, Wiener Neudorf, Lower Austria, Austria<br>
Weather: -7° Clear<br>
1st Sign of Paul’s arrival
.... Actually it was a normal morning and as usual I got up at 6 am start preparing the breakfast.错误直接发生在set txt命令中。
知道我为什么会犯错吗?
发布于 2014-06-14 12:58:56
你的括号放错了:
set txt to paragraphs of (read foo for (get eof foo) as «class utf8»)否则,您将尝试将list转换为utf8。
顺便说一句
for (get eof foo)是不必要的。
https://stackoverflow.com/questions/24218631
复制相似问题