Java tutorial
//package com.java2s; public class Main { public static int countLength(String string) { int length = 0; char[] chars = string.toCharArray(); for (int w = 0; w < string.length(); w++) { char ch = chars[w]; if (ch >= '\u0391' && ch <= '\uFFE5') { length++; length++; } else { length++; } } return length; } /** * get length of CharSequence * <p/> * <pre> * length(null) = 0; * length(\"\") = 0; * length(\"abc\") = 3; * </pre> * * @param str str * @return if str is null or empty, return 0, else return {@link * CharSequence#length()}. */ public static int length(CharSequence str) { return str == null ? 0 : str.length(); } }