Java Utililty Methods Unicode Escape

List of utility methods to do Unicode Escape

Description

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

Method

StringunicodeEscapeEncode(String unicode)
Performs escape encoding on the given string so that it can be represented using 1-byte characters.
StringBuilder result = new StringBuilder(unicode.length());
for (int i = 0, size = unicode.length(); i < size; ++i) {
    char character = unicode.charAt(i);
    if (character > '\u00ff') {
        result.append("\\u");
        String hex = Integer.toString(character, 16);
        for (int j = hex.length(); j < 4; ++j) {
            result.append("0");
...
StringunicodeHexEscapeJava(char ch)
converts a char to a java-style unicode escaped string
if (ch < 0x10) {
    return "\\u000" + Integer.toHexString(ch);
} else if (ch < 0x100) {
    return "\\u00" + Integer.toHexString(ch);
} else if (ch < 0x1000) {
    return "\\u0" + Integer.toHexString(ch);
return "\\u" + Integer.toHexString(ch);
...
StringunicodeUnescape(String st)
unicode Unescape
StringBuilder sb = new StringBuilder(st.length());
for (int i = 0; i < st.length(); i++) {
    char ch = st.charAt(i);
    if (ch == '\\') {
        char nextChar = (i == st.length() - 1) ? '\\' : st.charAt(i + 1);
        if (nextChar >= '0' && nextChar <= '7') {
            String code = "" + nextChar;
            i++;
...