I have a string that seems to contain a special €
character :
my_str # [1] "0€ de frais de courtage"
my_str == "0€ de frais de courtage" # [1] FALSE
gsub("€","X",my_str) # [1] "0€ de frais de courtage"
gsub("€","X","0€ de frais de courtage") # [1] "0X de frais de courtage"
I would like to replace it by the standard €
character i.e. the one I can type with Alt-gr + E
.
These strings come from file names I got with list.files
How can I do this ?
EDIT:
utf8ToInt(my_str)
# [1] 48 8364 32 100 101 32 102 114 97 105 115 32 100 101 32 99 111 117 114 116 97 103 101
utf8ToInt(stringi::stri_enc_toutf8("0€ de frais de courtage"))
# [1] 48 128 32 100 101 32 102 114 97 105 115 32 100 101 32 99 111 117 114 116 97 103 101
The strings appear identical but the
€
character is different.In my EDIT at the bottom of the post we see that the code for the regular
€
is128
while the code for the troublesome€
is8364
.and sure enough:
So the solution I was looking for is:
It replaces the "wrong"
€
character with a "regular"128
azerty alt gr + E
€
symbol.