Android examples for java.lang:String Unicode
count length of mixed unicode and ascii string
import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main{ public static int countEx(final CharSequence chars) { int count = 0; for (int i = 0; i < chars.length(); i++) { if (chars.charAt(i) >= 0 && chars.charAt(i) <= 127) count++;//from w w w . j a va 2s. c om else count += 2; } return count; } }