I have a string where some of the characters appear as unicode, e.g.: "bla bla bla \uf604 bla bla bla"
I tried doing string = string.replace("\uf604", "X")
, but nothing happens. I tried to decode the string to utf-8, but apparently that doesn't work in Python 3.
How can I replace the character?
In Python 3, this works (although the
print
may not, depending on your terminal):But perhaps you have a literal slash and not an escape code. Note the
print
difference:Use a escape slash to fix:
You can use the replace-method if you tell python to use a raw string:
results in
s ='bla bla bla X bla bla bla'