public static int calcUtfLength ( String str ) { final int strlen = str . length ( ) ; int utflen = 0 ; for ( int i = 0 ; i < strlen ; i ++ ) { int c = str . charAt ( i ) ; if ( ( c >= 0x0001 ) && ( c <= 0x007F ) ) { utflen ++ ; } else if ( c > 0x07FF ) { utflen += 3 ; } else { utflen += 2 ; } } return utflen ; }
Returns the length in bytes of a string s UTF - 8 encoding .