1

I have this string:

string <- "Blah blah \U0001d617\U0001d622\U0001d63a\U0001d633\U0001d630\U0001d62d\U0001d62d \U0001d61a\U0001d631\U0001d626\U0001d624\U0001d62a\U0001d622\U0001d62d\U0001d62a\U0001d634\U0001d635 blah blah"

when I pass it to cat i get this:

cat("Blah blah \U0001d617\U0001d622\U0001d63a\U0001d633\U0001d630\U0001d62d\U0001d62d \U0001d61a\U0001d631\U0001d626\U0001d624\U0001d62a\U0001d622\U0001d62d\U0001d62a\U0001d634\U0001d635 blah blah")
> Blah blah   blah blah

How can I convert the string into this:

> "Blah blah Payroll Specialist blah blah" 

I have looked at this post: R: Replacing foreign characters in a string, but I can't make it work.

The problem arises when I pull data from a webservice, so ideally the solution I am looking for is a solution that handles many/all possible ways to represent the letters. (e.g. bold, italic, etc.)

Thanks!

Jagge
  • 938
  • 4
  • 21

1 Answers1

1

There is library stringi (install.packages("stringi")) with stri_trans_nf* functions (Perform or Check For Unicode Normalization); check normalization forms for Unicode text for theory.

string <- "Blah blah \U0001d617\U0001d622\U0001d63a\U0001d633\U0001d630\U0001d62d\U0001d62d \U0001d61a\U0001d631\U0001d626\U0001d624\U0001d62a\U0001d622\U0001d62d\U0001d62a\U0001d634\U0001d635 blah blah"
library(stringi)
stri_trans_nfkc(string)  # [1] "Blah blah Payroll Specialist blah blah"
stri_trans_nfkd(string)  # [1] "Blah blah Payroll Specialist blah blah"
JosefZ
  • 28,460
  • 5
  • 44
  • 83