def subString(s, length):
us = unicode(s, 'utf-8')
gs = us.encode('gb2312')
n = int(length)
t = gs[:n]
while True:
try:
unicode(t, 'gbk')
break
except:
n -= 1
t = gs[:n]
return t.decode('gb2312')
Python 中文字符串的截取
最新推荐文章于 2022-11-28 11:06:46 发布