将十六进制字符串解码为中文字符 [英] Decode a hex string into Chinese characters

查看:52
本文介绍了将十六进制字符串解码为中文字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个十六进制代码:%E7%B5%99.我想把它转换成汉字.

print ("%E7%B5%99".decode('utf-8'))

这似乎不起作用.

应该给出答案:絙

解决方案

您需要先取消引用"百分比编码的字符串.然后从UTF8解码:

<预><代码>>>>s = "%E7%B5%99">>>打印 urllib.unquote(s).decode('utf8')絙

I have a hex code: %E7%B5%99. I want to convert it into Chinese characters.

print ("%E7%B5%99".decode('utf-8'))

This doesn't seem to work.

It should give the answer: 絙

解决方案

You need to "unquote" the percent encoded string first. Then decode from UTF8:

>>> s = "%E7%B5%99"
>>> print urllib.unquote(s).decode('utf8')
絙

这篇关于将十六进制字符串解码为中文字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆