use*_*604 11 python unicode-string string-length python-2.7
给定像" ?"(\xe2\x9c\xae)之类的字符,例如,可以是其他像" ?"," ?"或" ?")我想找到字符在屏幕上打印时所占用的"实际"长度
例如
len("?")
len("\xe2\x9c\xae")
Run Code Online (Sandbox Code Playgroud)
两者都返回3,但应该是1
你可以这样尝试:
\n\nunicodedata.normalize(\'NFC\', u\'\xe2\x9c\xae\')\nlen(u"\xe2\x9c\xae")\nRun Code Online (Sandbox Code Playgroud)\n\nUTF-8 是一种 unicode 编码,它使用多个字节来表示特殊字符。检查 unicodedata.normalize()
\n| 归档时间: |
|
| 查看次数: |
3059 次 |
| 最近记录: |