1. #!/usr/bin/env python
2. #coding=utf-8
3.
4. def get_Mutil_CnFirstLetter(str):
5. index = 0;
6. ""
7. "len(str)=%s"
8. while index < (len(str)-1):
9. #print "strReturnCn=%s" % strReturnCn
10. #print get_cn_first_letter(str[index:index+2],"GBK")
11. #print str[index:index+2]
12. "GBK")
13. index += 2;
14. return
15.
16. def get_cn_first_letter(str,codec="UTF8"):
17. if codec!="GBK":
18. if codec!="unicode":
19. str=str.decode(codec)
20. "GBK")
21.
22. if str<"/xb0/xa1" or str>"/xd7/xf9":
23. return ""
24. if str<"/xb0/xc4":
25. return "a"
26. if str<"/xb2/xc0":
27. return "b"
28. if str<"/xb4/xed":
29. return "c"
30. if str<"/xb6/xe9":
31. return "d"
32. if str<"/xb7/xa1":
33. return "e"
34. if str<"/xb8/xc0":
35. return "f"
36. if str<"/xb9/xfd":
37. return "g"
38. if str<"/xbb/xf6":
39. return "h"
40. if str<"/xbf/xa5":
41. return "j"
42. if str<"/xc0/xab":
43. return "k"
44. if str<"/xc2/xe7":
45. return "l"
46. if str<"/xc4/xc2":
47. return "m"
48. if str<"/xc5/xb5":
49. return "n"
50. if str<"/xc5/xbd":
51. return "o"
52. if str<"/xc6/xd9":
53. return "p"
54. if str<"/xc8/xba":
55. return "q"
56. if str<"/xc8/xf5":
57. return "r"
58. if str<"/xcb/xf9":
59. return "s"
60. if str<"/xcd/xd9":
61. return "t"
62. if str<"/xce/xf3":
63. return "w"
64. if str<"/xd1/x88":
65. return "x"
66. if str<"/xd4/xd0":
67. return "y"
68. if str<"/xd7/xf9":
69. return "z"
70.
71. if __name__== '__main__':
72. "我", "GBK")
73. "们", "GBK")
74. "他", "GBK")
75. "是", "GBK")
76. "大", "GBK")
77. "大埔的d")
python 提炼中文首字母 python提取首字母
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
MySQL查询某个字段含有字母数字的值
MySQL如何查询某个字段含有字母数字的值。
MySQL 字符串 正则表达式 -
java检测字符串是否包含数字和字母
Java检测字符串是否包含数字和字母
git 字符串 正则表达式 -
PHP提取中文首字母/php提出字符串首字母
<?php$PinYinDB=array( "a"=>-20319, "ai"=>-20317, "an"=>-20304, "ang"=>-20295, &nbs
职场 休闲 PHP提取中文首字母 php中文字母索引