将 u 转义的 Unicode 字符串转换为 ASCII [英] Converting a u escaped Unicode string to ASCII

查看:30
本文介绍了将 u 转义的 Unicode 字符串转换为 ASCII的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在阅读了关于iconvEncoding的所有内容后,我仍然感到困惑.

After reading all about iconv and Encoding, I am still confused.

我正在抓取 网页 我有一个看起来像这样的字符串:'prettyu003Du003Ebig'(在 R 控制台中显示为 'pretty\u003D\u003Ebig').我想将其转换为 ASCII 字符串,它应该是 'pretty=>big'.

I am scraping the source of a web page I have a string that looks like this: 'prettyu003Du003Ebig' (displayed in the R console as 'pretty\u003D\u003Ebig'). I want to convert this to the ASCII string, which should be 'pretty=>big'.

更简单,如果我设置

x <- 'pretty\u003D\u003Ebig'

如何对 x 执行转换以产生 pretty=>big?

How do I perform a conversion on x to yield pretty=>big?

有什么建议吗?

推荐答案

使用解析,但不评估结果:

Use parse, but don't evaluate the results:

x1 <- 'pretty\u003D\u003Ebig'
x2 <- parse(text = paste0("'", x1, "'"))
x3 <- x2[[1]]
x3
# [1] "pretty=>big"
is.character(x3)
# [1] TRUE
length(x3)
# [1] 1

这篇关于将 u 转义的 Unicode 字符串转换为 ASCII的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆