Python: How can I replace full-width characters with half-width characters?

后端 未结 6 1532
清酒与你
清酒与你 2020-12-16 00:51

If this was PHP, I would probably do something like this:

function no_more_half_widths($string){
  $foo = array(\'1\',\'2\',\'3\',\'4\',\'5\',\'6\',\'7\',\'8         


        
6条回答
  •  借酒劲吻你
    2020-12-16 01:27

    Regex approach

    >>> import re
    >>> re.sub(u"[\uff10-\uff19]",lambda x:chr(ord(x.group(0))-0xfee0),u"456")
    u'456'
    

提交回复
热议问题