def str_q2b(ustring):
"""全角转半角"""
ss = []
for s in ustring:
rstring = ""
for uchar in s:
inside_code = ord(uchar)
if inside_code == 12288:
inside_code = 32
elif 65281 <= inside_code <= 65374:
inside_code -= 65248
rstring += chr(inside_code)
ss.append(rstring)
return ''.join(ss)
def str_b2q(ustring):
"""全角转半角"""
ss = []
for s in ustring:
rstring = ""
for uchar in s:
inside_code = ord(uchar)
if inside_code == 32:
inside_code = 12288
elif 33 <= inside_code <= 126:
inside_code += 65248
rstring += chr(inside_code)
ss.append(rstring)
return ''.join(ss)
python 全角半角
最新推荐文章于 2024-04-18 18:00:00 发布