Get “actual” length of string in Unicode characters

后端 未结 2 920
悲哀的现实
悲哀的现实 2021-02-08 04:42

given a character like \"\" (\\xe2\\x9c\\xae), for example, can be others like \"Σ\", \"д\" or \"Λ\") I want to

2条回答
  •  囚心锁ツ
    2021-02-08 05: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()

提交回复
热议问题