如何将诸如“was\xe2\x80\x99t”之类的字符串解码回正常编码。
所以这个词实际上不是也不是“was\xe2\x80\x99t”? 例如:
print "\xe2\x80\x9cThings"
string = "\xe2\x80\x9cThings"
print string.decode('utf-8')
print string.encode('ascii', 'ignore')
“Things
“Things
Things
但我真的想得到“东西”。
或:
print "weren\xe2\x80\x99t"
string = "weren\xe2\x80\x99t"
print string.decode('utf-8')
print string.encode('ascii', 'ignore')
weren’t
weren’t
werent
但我真的不想
我该怎么做?
我绘制了最常见的奇怪字符,所以这是基于奥利弗W.答案的非常完整的答案。
这个功能并不理想,但它是最好的起点。 还有更多的字符定义:
http://utf8-chartable.de/unicode-utf8-table.pl?start=8192&number=128&utf8=string
http://www.utf8-chartable.de/unicode-utf8-table.pl?start=128&number=128&names=-&utf8=string-literal
。。。
应提供将unicode字符映射到其他unicode字符的转换映射(如果要重新编码,后者应在ASCII范围内):
相关问题 更多 >
编程相关推荐