Reverse the order of letters encoded in UTF-8
I have a variable encoded in Arabic (UTF-8), but in reverse order:
y <- "سنوت"
The correct word should be:
تونس # Tunisia for curious
I am trying to change this word like this:
rawToChar(rev(charToRaw(y)))
[1] "\xaa؈نٳ\xd8"
but it doesn't work. Please note that this works fine with encoded ASCII characters:
y <- "ydutsga"
> rawToChar(rev(charToRaw(y)))
[1] "agstudy"
+3
agstudy
source
to share
1 answer
Usage strsplit
to separate characters seems to work:
paste(rev(strsplit(y,"")[[1]]),collapse="")
[1] "تونس"
+4
James
source
to share