gpt4 book ai didi

ruby - 如何在 Ruby 中将字符串转换为 UTF8

转载 作者:数据小太阳 更新时间:2023-10-29 06:21:14 26 4
gpt4 key购买 nike

我正在编写一个使用 Hpricot 的爬虫。它从某个网页下载字符串列表,然后我尝试将其写入文件。编码有问题:

"\xC3" from ASCII-8BIT to UTF-8

我有在网页上呈现并以这种方式打印的项目:

Développement

str.encoding 返回 UTF-8,因此 force_encoding('UTF-8') 没有帮助。我如何将其转换为可读的 UTF-8?

最佳答案

您的字符串似乎被错误地编码了:

"Développement".encode("iso-8859-1").force_encoding("utf-8")
#=> "Développement"

关于ruby - 如何在 Ruby 中将字符串转换为 UTF8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17022394/

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