我使用hsparql庫運行返回德文文本的查詢;並因此返回iso-8859-1特殊字符。查詢結果中的iso-8859-1特殊字符錯誤
我使用writeFile
將查詢結果寫入文件,但未正確顯示特殊字符。 (查看與emacs的文件時)
當我不是寫show
函數的輸出到一個文件,我得到下面的輸出:
["B\195\188ro", ...]
打印出特殊字符這將意味着:["Büro", ....]
如何正確地將特殊字符寫入文件? (例如「Büro」正確顯示在文件輸出中。)
編輯: 我知道show顯示轉義字符。直接使用writeFile不起作用,我必須檢查錘子答案中給出的鏈接以找到修復。
EDIT2: 刪除,是錯誤的方法。
編輯3: 錘子的答案是正確的。找到解決方案只花了10分鐘,但我需要適應和集中。
我擡起頭IO在link
的解決方案是(文學Haskell):
> writeAllLabels = do
Running my Query (not shown, accesses the RDF TrippleStore):
> res <- (selectStr33 (unlines qAllLabels))
> outh <- openFile "/tmp/haskell_output.txt" WriteMode
this is the important line. If I would write "utf8" her instead of "latin1", I would get the wrong result again, i.e. as before asking the question...
> hSetEncoding outh latin1
> hPutStrLn outh res
> hClose outh
對於範圍爲0x80 - 0xBF的特殊字符,即特殊引號,應該使用** windows-1252 **。 – 2012-01-28 01:08:01