How to handle multibyte string in Python

后端 未结 2 1322
闹比i
闹比i 2020-12-19 10:32

There are multibyte string functions in PHP to handle multibyte string (e.g:CJK script). For example, I want to count how many letters in a multi bytes string by using

2条回答
  •  庸人自扰
    2020-12-19 11:16

    Try converting it to unicode first:

    print len(japanese.decode("utf-8"))
    

    gives 7. You are working on the utf-8 encoded string, which indeed has 21 bytes.

提交回复
热议问题