How can I create a UTF-8 string like "\u0531" in R, but taking the code "0531" as a variable?
I have a bad string (consisting of "UTF-8 codes in tags"), which I would like to dynamically turn into a good string (proper UTF-8 string).
badString <- "<U+0531><U+0067>"
goodString <- "Աg" # how can I generate that by a function?
turnBadStringToGoodString<- function (myString){
newString <- gsub("<U\\+([0-9]{4})>","\\u\\1",myString)
newString2 <- parse(text = paste0("'", newString, "'"))[[1]]
return (
newString2
)
}
turnBadStringToGoodString ( badString )
# returns an expression. What to do next?
Plase note that the desired outcome can be achieved by manually typing
"\u0531\u0067"
But how can that be done with a function? Thank you for ideas.
Also related: Converting a \u escaped Unicode string to ASCII