将Unicode转换为低/大写? [英] convert Unicode to lower/uppercase?
问题描述
有人有Python例程或模块将Unicode
字符串转换为小写(或大写)?
我实际需要做的是以
不区分大小写的方式比较一些字符串,所以我认为最简单的是先转换为
下限/上限。
可能所有字符串都来自latin-1字符集,所以我可以将
转换为8位latin-1,映射为小写,然后转换回来,但是
看起来相当麻烦。
-
Hallvard
Has someone got a Python routine or module which converts Unicode
strings to lowercase (or uppercase)?
What I actually need to do is to compare a number of strings in a
case-insensitive manner, so I assume it''s simplest to convert to
lower/upper first.
Possibly all strings will be from the latin-1 character set, so I could
convert to 8-bit latin-1, map to lowercase, and convert back, but that
seems rather cumbersome.
--
Hallvard
推荐答案
nospam写道:
nospam wrote:
有人有一个Python例程或模块将Unicode
字符串转换为小写(或大写)?
Has someone got a Python routine or module which converts Unicode
strings to lowercase (or uppercase)?
Toiled并提出:
Toiled and came up with:
print uabc ??ü ?" .upper()
ABC ??ü?
uABC ??ü.lower()
print u"abc??ü?".upper() ABC??ü?
u"ABC??ü".lower()
u''abc \\ xx4 \ xf6 \ xfc''
Peter
u''abc\xe4\xf6\xfc''
Peter
谢谢!
-
Hallvard
Thanks!
--
Hallvard
Peter Otten< __ ******* @ web.de>在消息新闻中写道:< bk ************* @ news.t-online.com> ...
Peter Otten <__*******@web.de> wrote in message news:<bk*************@news.t-online.com>...
nospam写道:
nospam wrote:
有人有一个Python例程或模块将Unicode
字符串转换为小写(或大写)吗?
Has someone got a Python routine or module which converts Unicode
strings to lowercase (or uppercase)?
Toiled并提出:
Toiled and came up with:
print u" abc ??ü?" .upper()ABC ??ü?
u" ABC ??ü" .lower( )
print u"abc??ü?".upper() ABC??ü?
u"ABC??ü".lower()
u''abc \ xe4 \ xf6 \ xfc''
彼得
u''abc\xe4\xf6\xfc''
Peter
但这确实无法正常工作。根据Unicode规范和
德语使用?的大写字母。实际上是SS,即单个
字符?应大写为两个字符。
Jim Allan
But that really doesn''t work properly. According to Unicode specs and
German usage the uppercase of "?" is actually "SS", that is the single
character "?" should uppercase to two characters.
Jim Allan
这篇关于将Unicode转换为低/大写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!