我正在寻找一个python代码,它将采用一个非unicode字符串,例如"ab <U0054><U0064>"
,并用它的unicode等价物替换它,即:u"ab \u0054\u0064"
或u"ab Td"
有没有一种比这个更像Python的写作方式?你知道吗
def replace_unicode(s):
while True:
i = s.find('<U')
if i == -1:
break
s = s.replace(s[i:i+7], unichr(int(s[i+2:i+6], 16)))
return s
Tags:
这个避免了无限循环+中断,而是使用^{} :
相关问题 更多 >
编程相关推荐