Java Unicode String length

后端 未结 5 703
孤独总比滥情好
孤独总比滥情好 2020-12-13 03:41

I am trying hard to get the count of unicode string and tried various options. Looks like a small problem but struck in a big way.

Here I am trying to get the length

5条回答
  •  执笔经年
    2020-12-13 04:02

    This is the new way to calculate the length of a Java String taking into account the Unicode characters.

    int unicodeLength = str.codePointCount(0, str.length);
    

提交回复
热议问题