转换utf8代码点字符串,例如< U + 0161>到utf8 [英] convert utf8 code point strings like <U+0161> to utf8

查看:133
本文介绍了转换utf8代码点字符串,例如< U + 0161>到utf8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本文件,其中包含Unicode字符的某种后备转换(尖括号中的Unicode代码点).所以它包含例如foo<U+017E>bar,应为foošbar". R中是否有一种简单的方法可以将这些字符转换为整个文件为UTF8?不幸的是,我在Windows上,找不到支持的UTF-8语言环境.

I have a text file which contains some kind of fallback conversions of Unicode characters (the Unicode code points in angle brackets). So it contains e.g. foo<U+017E>bar which should be "foošbar". Is there an easy way in R to convert the whole file to UTF8 with these characters converted? Unfortunately I am on Windows and can't find a supported UTF-8 locale.

推荐答案

也许:

library(stringi)
library(magrittr)

"foo<U+0161>bar and cra<U+017E>y" %>% 
  stri_replace_all_regex("<U\\+([[:alnum:]]+)>", "\\\\u$1") %>% 
  stri_unescape_unicode() %>% 
  stri_enc_toutf8()
## [1] "foošbar and cražy"

可能有效(我不需要在macOS上进行最后一次转换,但在Windows上则可以.)

may work (I don't need the last conversion on macOS but you may on Windows).

这篇关于转换utf8代码点字符串,例如&lt; U + 0161&gt;到utf8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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