How can you obtain the total characters of a String, considering that it could have supplementary characters which takes 2 code units to be encoded.
Example:
String strTest = "a𐐀"; //Supplementary character
System.out.println(strTest.length());
Output:
3
As we can see if we use length() we obtain 3 instead of 2. What I want to obtain is the number of characters for a given String, not the number of code units.
Use:
string.codePointCount(0, string.length())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With