Java Unicode Create toUnicodeEscape(char c)

Here you can find the source of toUnicodeEscape(char c)

Description

Encode a single char in Unicde BMP as a Java Unicode escape sequence.

License

Open Source License

Parameter

Parameter Description
c input char

Return

string on the form "\\uXXXX", where XXXX are hexadecimal digits, always zero-padded.

Declaration

public static String toUnicodeEscape(char c) 

Method Source Code

//package com.java2s;

public class Main {
    private static final char[] HEX = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e',
            'f' };

    /**/*from  www  .  jav  a2 s. c  o  m*/
     * Encode a single char in Unicde BMP as a Java Unicode escape sequence.
     * @param c input char
     * @return string on the form <code>"\\uXXXX"</code>, where XXXX are hexadecimal
     * digits, always zero-padded.
     */
    public static String toUnicodeEscape(char c) {
        char[] result = { '\\', 'u', 0, 0, 0, 0 };
        result[2] = HEX[(c >>> 12) & 0xF];
        result[3] = HEX[(c >>> 8) & 0xF];
        result[4] = HEX[(c >>> 4) & 0xF];
        result[5] = HEX[c & 0xF];
        return new String(result);
    }
}

Related

  1. toUnicode(String theString, boolean escapeSpace)
  2. toUnicode(String value)
  3. toUnicode(StringBuilder strBuilder, char ch)
  4. toUnicodeBytes(String str)
  5. toUnicodeEncoded(String data)
  6. toUnicodeEscape(int ch)
  7. toUnicodeLiteral(String s)
  8. toUnicodePoint(char c)
  9. toUnicodeRepresentation(String str)