vikino
vikino

Reputation: 109

How to convert text from one character set to another?

i have following problem: i need to convert this text: "test+%2B%C4%8D%C5%A5%C5%BE%C3%BD" to this "test +čťžý" i can do it online using this website : https://2cyr.com/decode/ on the website it says that the source text is in "WINDOWS-1251" character set and i need it to be in is "UTF-8".

in other words, i need to see the accented characters like this "čšť" not like this "%2B%C4" how can i achieve this? i tried to google it but none of the solutions i found help me. Thank you.

Upvotes: 1

Views: 177

Answers (1)

Douglas Storz
Douglas Storz

Reputation: 86

The function unquote from Python's urllib will convert these characters from their %XX escaped forms back into UTF-8. Documentation here: https://docs.python.org/3/library/urllib.parse.html#urllib.parse.unquote

>>> from urllib.parse import unquote
>>> unquote('test+%2B%C4%8D%C5%A5%C5%BE%C3%BD')
'test++čťžý'

Upvotes: 3

Related Questions