Java Unicode to String unicodeToString(int unicode)

Here you can find the source of unicodeToString(int unicode)

Description

unicode To String

License

Apache License

Declaration

static String unicodeToString(int unicode) 

Method Source Code

//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

public class Main {
    static String unicodeToString(int unicode) {
        switch (unicode) {
        case 0x00:
            return "\\0";
        case 0x08:
            return "\\b";
        case 0x09:
            return "\\t";
        case 0x10:
            return "\\n";
        case 0x0C:
            return "\\f";
        case 0x0D:
            return "\\r";
        case 0x22:
            return "\\\"";
        case 0x27:
            return "\\\'";
        case 0x5C:
            return "\\\\";
        default:/*from w w w. j av  a2 s . c  om*/
            if (0x20 <= unicode && unicode <= 0x7E) {
                return (new Character((char) unicode)).toString();
            } else {
                int ct[] = new int[4];
                ct[0] = (unicode & 0xF000) >>> 12;
                ct[1] = (unicode & 0x0F00) >>> 8;
                ct[2] = (unicode & 0x00F0) >>> 4;
                ct[3] = (unicode & 0x000F);

                char[] temp = { '\\', 'u', 'g', 'g', 'g', 'g' };

                for (int i = 0; i < 4; i++) {
                    int tempint = (ct[i] < 10 ? ct[i] + (int) '0' : ct[i] - 10 + (int) 'A');
                    temp[(i + 2)] = (char) tempint;
                }
                return new String(temp);
            }
        }
    }
}

Related

  1. Unicode2Str(String s)
  2. unicode2String(String unicodeStr)
  3. unicodeStringToPrettyString(String s)
  4. unicodeToAscii(String name, StringBuffer result)
  5. unicodeToAscii(String theString)
  6. unicodeToString(String escaped)
  7. unicodeToString(String hex)
  8. unicodeToString(String unicodeStr)