Search code examples
pythonascii

How do I remove/replace the ⁿ character from a string?


string = "000000ⁿ0000"
    
string.replace('ⁿ', "-")
string.replace('\u207f', "-")
    
print(string)

Error:

return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u207f' in position 6: character maps to <undefined>

Explicitly specifying utf-8 didn't help


Solution

  • replace returns what you want, there is no side effect.

    string = "000000ⁿ0000"
    ok = string.replace('ⁿ','-')
    print(string)
    #000000ⁿ0000
    print(ok)
    #000000-0000