本文介绍了Python:检查字符串是否包含中文字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
一个字符串可能是这个
ipath="./data/NCDC/上海/虹桥/9705626661750dat.txt"或者这个
ipath = './data/NCDC/ciampino/6240476818161dat.txt'我怎么知道第一个字符串包含chinese?
我觉得这个答案可能有帮助:使用 Python 查找字符串中的所有中文文本并正则表达式
但没有成功:
导入重新ipath="./data/NCDC/上海/虹桥/9705626661750dat.txt"re.findall(ur'[\u4e00-\u9fff]+', ipath) # =>[] 解决方案匹配的字符串也应该是 unicode
>>>进口重新>>>ipath=u"./data/NCDC/上海/虹桥/9705626661750dat.txt">>>re.findall(r'[\u4e00-\u9fff]+', ipath)[u'\u4e0a\u6d77', u'\u8679\u6865']A string maybe this
ipath= "./data/NCDC/上海/虹桥/9705626661750dat.txt"or this
ipath = './data/NCDC/ciampino/6240476818161dat.txt'How do I know the first string contains chinese?
I find this answer maybe helpful: Find all Chinese text in a string using Python and Regex
but it didn't work out:
import re ipath= "./data/NCDC/上海/虹桥/9705626661750dat.txt" re.findall(ur'[\u4e00-\u9fff]+', ipath) # => []解决方案
The matched string should be unicode as well
>>> import re >>> ipath= u"./data/NCDC/上海/虹桥/9705626661750dat.txt" >>> re.findall(r'[\u4e00-\u9fff]+', ipath) [u'\u4e0a\u6d77', u'\u8679\u6865']
更多推荐
Python:检查字符串是否包含中文字符?
发布评论