def convert_to_unicode(text):
return_str = ''
for character in text.split('%u'):
if character:
chr_code = int(character, 16)
return_str += chr(chr_code)
return return_str
text = '%u062a%u0633%u062a'
print(convert_to_unicode(text))
def convert_to_unicode(text: str):
# Replace %.
text = text.replace('%', '\\')
# Escape unicode into character.
text = text.encode().decode('unicode-escape')
return text
您可以通过%u拆分字符十六进制值,然后使用内置函数
chr
查找unicode字符。在输出:
^{pr2}$或者您可以使用unicode转义,如another answer中的blhsing。在
一种简单的方法是将
%
替换为\
,使其成为带有转义unicode字符的python文本,然后用unicode-escape
对其进行解码。在相关问题 更多 >
编程相关推荐