内容简介:翻译自:https://stackoverflow.com/questions/2422177/python-how-can-i-replace-full-width-characters-with-half-width-characters
如果这是 PHP
,我可能会这样做:
function no_more_half_widths($string){
$foo = array('1','2','3','4','5','6','7','8','9','10')
$bar = array('1','2','3','4','5','6','7','8','9','10')
return str_replace($foo, $bar, $string)
}
我在 python 中尝试过.translate函数,它表明数组的大小不同.我认为这是因为个别字符以utf-8编码.有什么建议?
内置的unicodedata模块可以做到:
>>> import unicodedata
>>> foo = u'1234567890'
>>> unicodedata.normalize('NFKC', foo)
u'1234567890'
“NFKC”代表“ Normalization Form KC [兼容性分解,然后是规范组合]”,并用半宽的字符替换全宽字符,即 Unicode equivalent .
请注意,它还可以同时对各种其他内容进行标准化,例如单独的重音符号和罗马数字符号.
翻译自:https://stackoverflow.com/questions/2422177/python-how-can-i-replace-full-width-characters-with-half-width-characters
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- 字符串、字符处理总结
- XML 非法字符(转义字符)
- 查找一个字符串中最长不含重复字符的子字符串,计算该最长子字符串的长度
- php删除字符串最后一个字符
- 高频算法面试题(字符串)leetcode 387. 字符串中的第一个唯一字符
- oracle查看字符集 修改字符集
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Big Java Late Objects
Horstmann, Cay S. / 2012-2 / 896.00元
The introductory programming course is difficult. Many students fail to succeed or have trouble in the course because they don't understand the material and do not practice programming sufficiently. ......一起来看看 《Big Java Late Objects》 这本书的介绍吧!