gpt4 book ai didi

html - 使用 "cat"将非英文字符写入 .html 文件(在 R 中)

转载 作者:可可西里 更新时间:2023-11-01 13:16:35 25 4
gpt4 key购买 nike

这是显示问题的代码:

myPath = getwd()
cat("abcd", append = T, file =paste(myPath,"temp1.html", sep = "\\")) # This is fine
cat("<BR/><BR/><BR/>", append = T, file =paste(myPath,"temp1.html", sep = "\\")) # This is fine
cat("שלום", append = F, file =paste(myPath,"temp1.html", sep = "\\")) # This text gets garbled when the html is opened using google chrome on windows 7.
cat("שלום", append = F, file =paste(myPath,"temp1.txt", sep = "\\")) # but if I open this file in a text editor - the text looks fine

# The text in the HTML folder would look as if I where to run this in R:
(x <- iconv("שלום", from = "CP1252", to = "UTF8") )
# But if I where to try and put it into the file, it wouldn't put anything in:
cat(x, append = T, file =paste(myPath,"temp1.html", sep = "\\")) # empty

编辑:我也试过使用以下编码(没有成功)

ff <-file(paste(myPath,"temp1.html", sep = "\\"), encoding="CP1252")
cat("שלום", append = F, file =ff)
ff<-file(paste(myPath,"temp1.html", sep = "\\"), encoding="utf-8")
cat("שלום", append = F, file =ff)
ff<-file(paste(myPath,"temp1.html", sep = "\\"), encoding="ANSI_X3.4-1986")
cat("שלום", append = F, file =ff)
ff<-file(paste(myPath,"temp1.html", sep = "\\"), encoding="iso8859-8")
cat("שלום", append = F, file =ff)

有什么建议吗?谢谢。

最佳答案

这样试试

cat("abcd", file = (con <- file("temp1.html", "w", encoding="UTF-8"))); close(con)

关于html - 使用 "cat"将非英文字符写入 .html 文件(在 R 中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7483742/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com