Python的ASCII, UTF-8 相互转换
2017-08-16 19:28
381 查看
如果原来的string是utf-8编码的,想转成ascii编码,那么:
例如,
utf-8编码: ‘\xe4\xbd\xa0\xe5\xa5\xbd’
转成 ascii编码: u’\u4f60\u597d’
方法是:str.decode(‘utf-8’)
反之,如果原来的string是ascii编码的,想转成utf-8编码,那么:
例如,
ascii编码: u’\u4f60\u597d’
转成 utf-8编码:’\xe4\xbd\xa0\xe5\xa5\xbd’
方法是:str.decode(‘ascii’)
例如,
str=“你好”
utf-8编码: ‘\xe4\xbd\xa0\xe5\xa5\xbd’
转成 ascii编码: u’\u4f60\u597d’
方法是:str.decode(‘utf-8’)
反之,如果原来的string是ascii编码的,想转成utf-8编码,那么:
例如,
str=“你好”
ascii编码: u’\u4f60\u597d’
转成 utf-8编码:’\xe4\xbd\xa0\xe5\xa5\xbd’
方法是:str.decode(‘ascii’)
相关文章推荐
- Python的ASCII, GB2312, Unicode , UTF-8 相互转换
- Python的ASCII, GB2312, Unicode , UTF-8 相互转换
- Python的ASCII, GB2312, Unicode , UTF-8 相互转换
- Python的ASCII, GB2312, Unicode , UTF-8 相互转换
- Python的ASCII, GB2312, Unicode , UTF-8 相互转换
- ASCII,UTF-8,Unicode字符串相互转换(转)
- C++编程:ASCII,UTF-8,Unicode字符串相互转换
- ASCII,UTF-8,Unicode字符串相互转换(转)
- windows ASCII,UTF-8,Unicode字符串相互转换
- utf,unicode,ascii字符串之间的相互转换
- 字符串UTF-8与ASCII相互转换
- ASCII,UTF-8,Unicode字符串相互转换
- ASCII,UTF-8,Unicode字符串相互转换
- ASCII,UTF-8,Unicode字符串相互转换
- 【python】time,datetime,string相互转换
- gb2312 utf-8 相互转换
- ANSI,UNICODE, UTF-8 字符串之间的相互转换
- JAVA字符编码系列二:Unicode,ISO-8859,GBK,UTF-8编码及相互转换
- C/C++中ASCII与Unicode字符串相互转换
- Python ASCII码与字符相互转换