且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用R转换文件编码? (ANSI到UTF-8)

更新时间:2023-11-27 19:19:52

可以使用iconv: / p>

  writeLines(iconv(readLines(tmp.html),from =ANSI_X3.4-1986,=UTF8 ),tmp2.html)

tmp2.html应该是utf-8。 >




Henrik于2015年6月编辑:

Windows的一个工作解决方案来自评论如下:

  writeLines(iconv(readLines(tmp.html),from =ANSI_X3.4 -1986,to =UTF8),
文件(tmp2.html,encoding =UTF-8))


I wish to convert an HTML file encoded in ANSI to UTF-8, using R.

Is there a tool, or a combination of tools, that can make this work?

Thanks.

Edit: o.k, I've narrowed my problem to another one. It is re-posted here: Using "cat" to write non-English characters into a .html file (in R)

you can use iconv:

writeLines(iconv(readLines("tmp.html"), from = "ANSI_X3.4-1986", to = "UTF8"), "tmp2.html")

tmp2.html should be utf-8.


Edit by Henrik in June 2015:
A working solution for Windows distilled from the comments is as follows:

writeLines(iconv(readLines("tmp.html"), from = "ANSI_X3.4-1986", to = "UTF8"), 
           file("tmp2.html", encoding="UTF-8"))