To determine if a character is Chinese

string’scoding should be unicode

to know if one character is Chinese

we can decode utf-8 to unicode

def is_chinese(uchar):
if uchar >= u'\u4e00' and uchar<=u'\u9fa5':
return True
return False


In Python, convert utf-8 to unicode


convert unicode to utf-8



for i in '下:@uVT4HLJLA: 二、我是用MAC的,所以可以骂你脑残'.decode('utf-8'):
    print i, is_chinese(i)

下 True
: False
@ False
u False
V False
T False
4 False
H False
L False
J False
L False
A False
: False
二 True
、 False
我 True
是 True
用 True
M False
A False
C False
的 True
, False
所 True
以 True
可 True
以 True
骂 True

Leave a Reply

Your email address will not be published.

Notice: Undefined index: cookies in /var/www/html/wp-content/plugins/live-composer-page-builder/modules/tp-comments-form/module.php on line 1638