You can use java.text.BreakIterator to find the gaps between the graphemes ("visual symbols") and count them. Here is an example:
import java.text.BreakIterator; .. int graphemeLength(String str) { BreakIterator iter = BreakIterator.getCharacterInstance(); iter.setText(str); int count = 0; while (iter.next() != BreakIterator.DONE) count++; return count; }
Now graphemeLength("อภิชาติ") will return 5.
source share