(编辑:现在引用Unbaking mojibake)
源文件:Android手机.vcf联系人文件 目的地:Windows 7用户联系人文件(导入.vcf)
结果联系信息: 韩国mojibake的名称字段: '_곗퐫李쏀__ㅻ━肄섏떎留_'
结果应该只是韩文。经过一些研究后,我猜测有一些与EUC-kr
相关的编码问题,因为mojibake中有汉字。但真的不知道......
这是Python的结果: _°¤¤Ô¤½¤É¤§ì°½í__¤ë|¬ì½¤Ô¤μ¤Â¤°¤Ô¤¨¤¤¤«§§_
显然这不正确。所以仍然坚持......
# ?'windows-1252' -> 949?
encoding1 = 'ISO-2022-KR' #could not encode
encoding1 = 'windows-1252' #could not encode
encoding1 = 'iso-8859-1' #could not encode
encoding1 = 'utf8' #does nothing
encoding1 = 'euc-kr'
import chardet
import chardet
import codecs
mojibake = '_곗퐫 李쏀__ㅻ━肄섏떎留_'
try:
encoded_str = mojibake.encode(encoding1)
except UnicodeEncodeError:
print("error: could not encode")
encoded_str = None
if encoded_str:
detected_encoding = chardet.detect(encoded_str)["encoding"]
print('detected_encoding',detected_encoding)
try:
correct_str = encoded_str.decode(detected_encoding)
except UnicodeEncodeError:
print("could not decode encoded_str as", detected_encoding)
print(correct_str)