Android String Length Check strLength(String str)

Here you can find the source of strLength(String str)

Description

str Length

Declaration

public static int strLength(String str) 

Method Source Code



public class Main {

    public static int strLength(String str) {
        int valueLength = 0;
        String chinese = "[\u0391-\uFFE5]";
        if (!isEmpty(str)) {
            //from   w  w  w. j  av a2 s .  c o m
            for (int i = 0; i < str.length(); i++) {
                
                String temp = str.substring(i, i + 1);
                
                if (temp.matches(chinese)) {
                    
                    valueLength += 2;
                } else {
                    
                    valueLength += 1;
                }
            }
        }
        return valueLength;
    }

    public static boolean isEmpty(String str) {
        return str == null || str.trim().length() == 0;
    }
}

Related

  1. checkMinLength(final String x, final int min)
  2. isStringWithLen(Object obj, int len)
  3. isStringWithLen(String str, int len)
  4. strlen(String str, String charset)
  5. strlen(String str, String charset)