Reputation: 684
I have this character:
u<- "U+1F37A"
# output needed is "\U0001F37A"
So I used the gsub() function like this-
v <- gsub("U\\+", "\\u000", u, fixed= F)
# however I am keep getting "U0001F37A" without "\" in front
# OR
# an error Error: nul character not allowed (line 1)
I have looked around Stack and there were couple of questions removing "\U000.." not inserting. Try to "reverse engineer" a bit, but I failed.
I have also read this http://uc-r.github.io/regex but no luck.
Upvotes: 1
Views: 210
Reputation: 887128
We can use double escape
u1 <- sub("U\\+", "\\\\U000", u)
cat(u1, sep="\n")
#\U0001F37A
Upvotes: 1