Get “actual” length of string in Unicode characters

拜拜、爱过 提交于 2019-12-03 06:54:08

You may try like this:

unicodedata.normalize('NFC', u'✮')
len(u"✮")

UTF-8 is an unicode encoding which uses more than one byte for special characters. Check unicodedata.normalize()

Simon Richter

My answer to a similar question:

You are looking for the rendering width from the current output context. For graphical UIs, there is usually a method to directly query this information; for text environments, all you can do is guess what a conformant rendering engine would probably do, and hope that the actual engine matches your expectations.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!