- 浏览: 3362289 次
- 性别:
- 来自: 珠海
文章分类
- 全部博客 (1633)
- Java (250)
- Android&HTML5 (111)
- Struts (10)
- Spring (236)
- Hibernate&MyBatis (115)
- SSH (49)
- jQuery插件收集 (55)
- Javascript (145)
- PHP (77)
- REST&WebService (18)
- BIRT (27)
- .NET (7)
- Database (105)
- 设计模式 (16)
- 自动化和测试 (19)
- Maven&Ant (43)
- 工作流 (36)
- 开源应用 (156)
- 其他 (16)
- 前台&美工 (119)
- 工作积累 (0)
- OS&Docker (83)
- Python&爬虫 (28)
- 工具软件 (157)
- 问题收集 (61)
- OFbiz (6)
- noSQL (12)
最新评论
-
HEZR曾嶸:
你好博主,这个不是很理解,能解释一下嘛//左边+1,上边+1, ...
java 两字符串相似度计算算法 -
天使建站:
写得不错,可以看这里,和这里的这篇文章一起看,有 ...
jquery 遍历对象、数组、集合 -
xue88ming:
很有用,谢谢
@PathVariable映射出现错误: Name for argument type -
jnjeC:
厉害,困扰了我很久
MyBatis排序时使用order by 动态参数时需要注意,用$而不是# -
TopLongMan:
非常好,很实用啊。。
PostgreSQL递归查询实现树状结构查询
Python 字符编码判断 http://blog.sina.com.cn/s/blog_44c781ec0100sgsh.html
http://my.oschina.net/eonezhang/blog/125440
http://my.oschina.net/eonezhang/blog/125440
def is_chinese(uchar): """判断一个unicode是否是汉字""" if uchar >= u'\u4e00' and uchar<=u'\u9fa5': return True else: return False def is_number(uchar): """判断一个unicode是否是数字""" if uchar >= u'\u0030' and uchar<=u'\u0039': return True else: return False def is_alphabet(uchar): """判断一个unicode是否是英文字母""" if (uchar >= u'\u0041' and uchar<=u'\u005a') or (uchar >= u'\u0061' and uchar<=u'\u007a'): return True else: return False def is_other(uchar): """判断是否非汉字,数字和英文字符""" if not (is_chinese(uchar) or is_number(uchar) or is_alphabet(uchar)): return True else: return False def B2Q(uchar): """半角转全角""" inside_code=ord(uchar) if inside_code<0x0020 or inside_code>0x7e: #不是半角字符就返回原来的字符 return uchar if inside_code==0x0020: #除了空格其他的全角半角的公式为:半角=全角-0xfee0 inside_code=0x3000 else: inside_code+=0xfee0 return unichr(inside_code) def Q2B(uchar): """全角转半角""" inside_code=ord(uchar) if inside_code==0x3000: inside_code=0x0020 else: inside_code-=0xfee0 if inside_code<0x0020 or inside_code>0x7e: #转完之后不是半角字符返回原来的字符 return uchar return unichr(inside_code) def stringQ2B(ustring): """把字符串全角转半角""" return "".join([Q2B(uchar) for uchar in ustring]) def uniform(ustring): """格式化字符串,完成全角转半角,大写转小写的工作""" return stringQ2B(ustring).lower() def string2List(ustring): """将ustring按照中文,字母,数字分开""" retList=[] utmp=[] for uchar in ustring: if is_other(uchar): if len(utmp)==0: continue else: retList.append("".join(utmp)) utmp=[] else: utmp.append(uchar) if len(utmp)!=0: retList.append("".join(utmp)) return retList if __name__=="__main__": #test Q2B and B2Q for i in range(0x0020,0x007F): print Q2B(B2Q(unichr(i))),B2Q(unichr(i)) #test uniform ustring=u'中国 人名a高频A' ustring=uniform(ustring) ret=string2List(ustring) print ret
发表评论
-
Htmlunit使用
2015-04-11 20:12 1061http://my.oschina.net/u/852445/ ... -
垂直爬虫 webmagic
2014-09-05 20:24 2999新版文档地址 http://webmagic.io/docs/ ... -
python Tkinter的一些记录
2013-10-14 11:06 17541. Label里面的文本对齐方式:http://www.hi ... -
Python中执行外部命令并捕获双向输出
2013-10-12 15:08 2401原文:http://my.oschina.net/qihh/b ... -
python: 界面开发Tkinter
2013-10-10 16:38 1647python GUI开发 工具选择 http://blog.c ... -
Python多线程学习
2013-10-08 09:39 1408http://www.cnblogs.com/tqsummer ... -
问题: Max retries exceeded with url
2013-10-07 11:36 29264解决一: http://stackoverflow.com/q ... -
python + request + lxml的几个例子
2013-10-06 22:09 4438例子没有加入失败后重做的功能,这个也可以考虑增加。 第三个例子 ... -
python对文件的创建等处理
2013-10-06 21:24 1142http://www.qttc.net/201209207.h ... -
python: json,base64 的使用
2013-10-06 19:12 2958JSON 1. import json 2. json.dum ... -
python requests 下载图片和数据库读取
2013-10-02 15:56 18479python requests 下载图片 de ... -
python类型转换
2013-10-01 14:12 1039http://jayzotion.iteye.com/blog ... -
Python:数组、列表(list)、字典(dict)、字符串(string)常用基本操作小结
2013-09-30 13:07 13669连接 list 与分割字符串h ... -
Python模块学习 ---- datetime
2013-09-30 09:39 2181[Python Tip]如何计算时间 ... -
python html parser库lxml的介绍和使用
2013-09-30 09:39 7345使用由 Python 编写的 lxml 实现高性能 XML 解 ... -
用Python操作Mysql和中文问题
2013-09-29 13:55 2613http://www.iteye.com/topic/5730 ... -
Python 字符串操作(截取/替换/查找/分割)
2013-09-29 13:01 6186python字符串连接 先介绍下效率比较低的,有些新手朋友就会 ... -
Python中使用中文
2013-09-29 10:25 1116http://blog.csdn.net/kernelspir ... -
Beautiful Soup 中文教程
2013-09-29 09:36 2689http://www.pythonclub.org/modul ... -
python + request + pyquery[安装失败]
2013-09-28 20:51 2147比urllib好用的requests http://www.b ...
相关推荐
本文实例讲述了python判断字符串编码的方法。分享给大家供大家参考,具体如下: 安装chardet模块 chardet文件夹放在/usr/lib/python2.4/site-packages目录下 [root@sha-sso-data01 chardet]# python Python 2.4.3 ...
本文实例讲述了Python字符编码判断方法。分享给大家供大家参考,具体如下: 方法一: isinstance(s, str) 用来判断是否为一般字符串 isinstance(s, unicode) 用来判断是否为unicode 或 if type(str).__name__!=...
Python字符串的驻留机制、查询操作、大小写转换、内容对齐、劈分方法、判断字符串的操作方法、比较、切片、格式化、编码和解码等基本操作的整理
主要介绍了python使用chardet判断字符串编码的方法,涉及Python编码的技巧,具有一定参考借鉴价值,需要的朋友可以参考下
python判断文件和字符串编码类型可以用chardet工具包,可以识别大多数的编码类型。但是前几天在读取一个Windows记事本保存的txt文件时,GBK却被识别成了KOI8-R,无解。 然后就自己写了个简单的编码识别方法,代码...
Python判断两个相等的中文字符串为false,将两个待比较的字符串都把unicode编码设为‘utf-8’也不能解决问题,具体原因如下: 1.首先查看待比较两个字符串的编码格式 ,使用命令 import chardet ...... string_code...
Python中chardet 用来实现字符串/文件编码检测模板 1、chardet下载与安装 下载地址:http://pypi.python.org/pypi/chardet 下载chardet后,解压chardet压缩包,直接将chardet文件夹放在应用程序目录下,就可以使用...
本文实例讲述了python检查字符串是否是正确ISBN的方法。分享给大家供大家参考。具体实现方法如下: def isISBN(isbn): """Checks if the passed string is a valid ISBN number.""" if len(isbn) != 10 or not ...
本文主要给大家介绍了下Python的一些内置字符串的方法,包括概览,字符串大小写转换,字符串格式输出,字符串搜索定位与替换,字符串的联合与分割,字符串条件判断,字符串编码
Python字符串及操作(一) 此片文章总结涉及到字符串的引入、使用、索引选取、连接重复以及成员判断 字符串(string) 字符串是以单引号’ ‘或者双引号“ “括起来的任意文本。 由于我是新手,只是进行所学内容的总结...
4.4 Python字符串类型 42 4.5 Python字符串处理 44 4.6 Python列表数据类型 48 4.7 Python元组数据类型 56 4.8 Python字典数据类型 58 4.9 Python集合数据类型 66 五、Python运算符 73 5.1 运算符介绍 73 5.2 算术...
用转义序列代表特殊的字符:字符串的运算:字符串的索引语法:说明:作用:字符串的切片:英文(slice)语法:语法说明:Python3中常用的序列函数:字符串编码转换函数:整数转换为字符串函数字符串构造函数:几个小练习判断回文...
├─千锋Python教程:第03章 字符串&布尔&空值(7集) │ │ .DS_Store │ │ │ ├─code │ │ 1、String(字符串).py │ │ 2、String的内置函数.py │ │ 3、布尔值和空值.py │ │ 4、变量的类型问题.py │ │ ...
总是绕不开对字符或字符串的处理,而在Golang语言中,对字符和字符串的处理方式可能和其他语言不太一样,比如Python或Java类的语言,本篇文章分享一些Golang语言下的Unicode和字符串编码。 Go语言字符编码 注意: 在...
15.15 C字符串转换为Python字符串 15.16 不确定编码格式的C字符串 15.17 传递文件名给C扩展 15.18 传递已打开的文件给C扩展 15.19 从C语言中读取类文件对象 15.20 处理C语言中的可迭代对象 15.21 诊断分析...
刚开始学习python,附件是本人python学习笔记记录,包括字符编码、格式化、字符串、条件判断和循环、函数等内容