Java tutorial
//package com.java2s; //License from project: Open Source License import android.text.TextUtils; public class Main { /** * counter ASCII character as one, otherwise two * * @param str * @return count */ public static int counterChars(String str) { // return if (TextUtils.isEmpty(str)) { return 0; } int count = 0; for (int i = 0; i < str.length(); i++) { int tmp = (int) str.charAt(i); if (tmp > 0 && tmp < 127) { count += 1; } else { count += 2; } } return count; } public static boolean isEmpty(String input) { if (input == null || "".equals(input) || "null".equals(input.toLowerCase())) return true; for (int i = 0; i < input.length(); i++) { char c = input.charAt(i); if (c != ' ' && c != '\t' && c != '\r' && c != '\n') { return false; } } return true; } }