使用pure&pythonic库将Unicode/UTF-8字符串转换为小/大写字母
-
23-09-2019 - |
题
我使用Google App Engine,无法使用任何C/C++扩展,只需pure&pythonic库即可将Unicode/UTF-8字符串转换为小写/大写。str.lower()和string。小写()不要。
解决方案
str
编码为UTF-8和 unicode
是两种不同的类型。不要使用 string
, ,在unicode对象上使用适当的方法:
>>> print u'ĉ'.upper()
Ĉ
解码/解码 str
到 unicode
使用前:
>>> print 'ĉ'.decode('utf-8').upper()
Ĉ
不隶属于 StackOverflow