Android Utililty Methods Unicode Convert

List of utility methods to do Unicode Convert

Description

The list of methods to do Unicode Convert are organized into topic(s).

Method

StringconvertToUnicode(byte[] b, boolean includesNull)
Converts the byte array provided to a unicode string.
if (b == null || b.length == 0) {
    return null;
int arrayLength = b.length;
if (!((arrayLength % 2) == 0)) {
    throw new IllegalArgumentException(
            "Byte array not of a valid form");
arrayLength = (arrayLength >> 1);
if (includesNull) {
    arrayLength -= 1;
char[] c = new char[arrayLength];
for (int i = 0; i < arrayLength; i++) {
    int upper = b[2 * i];
    int lower = b[(2 * i) + 1];
    if (upper < 0) {
        upper += 256;
    if (lower < 0) {
        lower += 256;
    if (upper == 0 && lower == 0) {
        return new String(c, 0, i);
    c[i] = (char) ((upper << 8) | lower);
return new String(c);
StringstringToUnicode(String strText)
string To Unicode
char c;
String strRet = "";
int intAsc;
String strHex;
for (int i = 0; i < strText.length(); i++) {
    c = strText.charAt(i);
    intAsc = (int) c;
    strHex = Integer.toHexString(intAsc);
...
Listunicode2han3last_direct(Character c)
unicodehanlasdirect
Integer code = (int) c.charValue();
if (code >= 44032 && code <= 55203) { 
    code -= 44032;
    Integer last = code % 28;
    code = (code / 28);
    Integer middle = code % 21;
    Integer first = code / 21;
    return Arrays.asList(concatAll(first_set[first],
...
Listunicode2han_str(String str)
unicodehastr
List<Byte> result = new ArrayList<Byte>();
char[] chars = str.toCharArray();
for (Character c : chars) {
    result.addAll(unicode2han3last_direct(c));
return result;
StringunicodeEscape(String s)
unicode Escape
StringBuilder sb = new StringBuilder();
boolean first = false;
for (int i = 0; i < s.length(); i++) {
    char c = s.charAt(i);
    if (checkTurkish(c)) {
        sb.append(c);
    } else {
        if (checkAscii(c)) {
...
StringgetEmojiByUnicode(int unicode)
get Emoji By Unicode
return new String(Character.toChars(unicode));
voidhiraganaToKatakana(byte[] b)
hiragana To Katakana
int len = b.length;
if ((len & 1) == 1) {
    b[len - 1] = '\0';
    len--;
for (int i = 0; i < len; i += 2) {
    int high = b[i] & 0xff;
    int low = b[i + 1] & 0xff;
...