Python: UTF8转换代码实例

这是生成Android联系人vcf文件时候,转UTF8编码的例子.

 

def Convert(s):  
    r=""
    for c in s:
        temp = hex(ord(c)).replace("0x","")
        if len(temp) == 1:
            temp='0'+temp
        r=r+"="+temp
    return "CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:"+r

posted @ 2013-02-06 22:22  shinedream  阅读(212)  评论(0编辑  收藏  举报