Java String Length Get lengthUnicode(String s)

Here you can find the source of lengthUnicode(String s)

Description

length Unicode

License

Open Source License

Declaration

public static int lengthUnicode(String s) 

Method Source Code

//package com.java2s;

public class Main {

    public static int lengthUnicode(String s) {
        if (s == null || s.length() == 0)
            return 0;

        int len = 0;
        for (int i = 0; i < s.length(); i++) {
            if ((int) s.charAt(i) > 127)
                len += 2;/*from  ww  w .j  a  v a  2 s.co m*/
            else
                len += 1;
        }
        return len;
    }

    public static int length(String s) {
        if (s == null || s.length() == 0)
            return 0;

        return s.length();
    }
}

Related

  1. lengthOfStartingWhitespace(String s)
  2. lengthOfString(final String cadena)
  3. lengthTokensField(String fieldName)
  4. lengthToString(double value, boolean proportional)
  5. lengthUCP(String s)
  6. lengthWithinLimits(String string, int min, int max)