当前位置: 代码迷 >> 综合 >> python-全角转半角
  详细解决方案

python-全角转半角

热度:13   发布时间:2024-01-16 12:28:26.0
def strQ2B(ustring):"""全角转半角"""rstring = ""for uchar in ustring:inside_code = ord(uchar)if inside_code == 12288:  # 全角空格直接转换inside_code = 32elif (inside_code >= 65281 and inside_code <= 65374):  # 全角字符(除空格)根据关系转化inside_code -= 65248# rstring += unichr(inside_code)rstring += chr(inside_code)return rstring

 

  相关解决方案