Reputation: 121568
I have some variable that are encoded in Arabic(UTF-8), but in the reverse order:
y <- "سنوت"
The right word should be :
تونس # Tunisia for curious
I am trying to reverse this word like this:
rawToChar(rev(charToRaw(y)))
[1] "\xaa؈نٳ\xd8"
but this doesn't work. Note that this works fine with ASCII encoded characters:
y <- "ydutsga"
> rawToChar(rev(charToRaw(y)))
[1] "agstudy"
Upvotes: 3
Views: 162
Reputation: 66834
Using strsplit
to separate the characters seems to work:
paste(rev(strsplit(y,"")[[1]]),collapse="")
[1] "تونس"
Upvotes: 4