以输入为GB18030编码字符串为例:

#把全角字符串转半角
def tobanjiao(string):
        ustring = string.decode('GB18030')
        rstring = ""
        for uchar in ustring:
                inside_code=ord(uchar)  
                if inside_code==0x3000:  
                        inside_code=0x0020  
                else:  
                        inside_code-=0xfee0  

                if inside_code<0x0020 or inside_code>0x7e:
                        rstring += uchar.encode('GB18030')
                else:
                        rstring += unichr(inside_code).encode('GB18030')

        return rstring;

  

相关文章:

  • 2021-11-16
  • 2022-12-23
  • 2021-10-29
  • 2021-12-02
  • 2021-06-11
  • 2021-11-22
猜你喜欢
  • 2021-12-14
  • 2022-12-23
  • 2021-06-21
  • 2022-12-23
  • 2021-08-15
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案