# -*- coding: utf-8 -*- # @Time : 18-9-13 下午12:16 # @Author : Felix Wang # 判斷一個字符是否為漢字,英文字母,數字,空還是其他 # 使用Unicode編碼來判斷 def is_chinese(uchar): """判斷一個unicode是否是漢字""" if u'\u4e00' <= uchar <= u'\u9fa5': return True else: return False def is_number(uchar): """判斷一個unicode是否是數字""" if u'\u0030' <= uchar <= u'\u0039': return True else: return False def is_alphabet(uchar): """判斷一個unicode是否是英文字母""" if (u'\u0041' <= uchar <= u'\u005a') or (u'\u0061' <= uchar <= u'\u007a'): return True else: return False def is_space(uchar): """判斷一個unicode是否是空字符串(包括空格,回車,tab)""" space = [u'\u0020', u'\u000A', u'\u000D', u'\u0009'] if uchar in space: return True else: return False def is_other(uchar): """判斷是否非漢字,數字,空字符和英文字符""" if not (is_space(uchar) or is_chinese(uchar) or is_number(uchar) or is_alphabet(uchar)): return True else: return False