Android String to Byte Array Convert getLengthByByte(String str)

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

Description

get Length By Byte

Declaration

public static int getLengthByByte(String str) 

Method Source Code

//package com.java2s;

public class Main {
    public static int getLengthByByte(String str) {
        int length = 0;
        if (str == null || str.length() == 0) {
            return length;
        }//from w  w w  .  j  a  v a2 s  .  co m

        for (int i = 0; i < str.length(); i++) {
            int ascii = Character.codePointAt(str, i);
            if (ascii >= 0 && ascii <= 255) {
                length++;
            } else {
                length += 2;
            }
        }
        return length;
    }
}

Related

  1. hexStringToByteArray(String hexa)
  2. toByte(String hexString)
  3. toByte(String hexString)
  4. toBytes(final String str)
  5. StringtoByte(String data)
  6. bytesStorage(String str)
  7. bytesStorage(String str)
  8. getBytes(String s)
  9. getBytes(String data)