1 回答

TA貢獻(xiàn)1843條經(jīng)驗(yàn) 獲得超7個(gè)贊
您可以組合函數(shù)utf8ToInt和as.hexmode,然后將轉(zhuǎn)義字符粘貼到:
as.html <- function(x) paste0("&x", as.hexmode(utf8ToInt(x)), ";")
as.html("\U0001f923")
#> [1] "&x1f923;"
您可以使用它來(lái)替換多字節(jié)字符,如下所示:
replace_multibytes <- function(x)
{
as.html <- function(x) paste0("&x", as.hexmode(utf8ToInt(x)), ";")
char_list <- as.list(unlist(strsplit(x, "")))
x <- sapply(char_list, function(y) if(length(charToRaw(y)) > 1) as.html(y) else y)
paste0(x, collapse = "")
}
所以現(xiàn)在你可以做
replace_multibytes("The following need replaced: \U0001f923 \U0001f924")
#> [1] "The following need replaced: &x1f923; &x1f924;"
- 1 回答
- 0 關(guān)注
- 113 瀏覽
添加回答
舉報(bào)