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

StringunicodeEscape(char c)
unicode Escape
if (c <= 0xf)
    return "\\u000" + Integer.toHexString(c);
else if (c <= 0xff)
    return "\\u00" + Integer.toHexString(c);
else if (c <= 0xfff)
    return "\\u0" + Integer.toHexString(c);
else
    return "\\u" + Integer.toHexString(c);
...
StringunicodeEscape(Character ch)
converts a Character to a java-style unicode escaped string
return unicodeHexEscapeJava(ch.charValue());
StringunicodeEscape(String s)
unicode Escape
StringBuilder sb = new StringBuilder();
for (int i = 0; i < s.length(); i++) {
    char c = s.charAt(i);
    if ((c >> 7) > 0) {
        sb.append("\\u");
        sb.append(hexChar[(c >> 12) & 0xF]); 
        sb.append(hexChar[(c >> 8) & 0xF]); 
        sb.append(hexChar[(c >> 4) & 0xF]); 
...
StringunicodeEscape(String s)
unicode Escape
StringBuffer sb = new StringBuffer();
for (int i = 0; i < s.length(); i++) {
    char c = s.charAt(i);
    sb.append(unicodeEscape(c));
return sb.toString();
intunicodeEscape(StringBuilder result, int in, int index)
Given a char, and its location in a StringBuilder, replace it with an escaped unicode if necessary
if (in >= 32 && in <= 127) {
    return index;
if (in > '\uffff') {
    final char[] surrogatePair = Character.toChars(in);
    final String first = hex(surrogatePair[0]);
    final String second = hex(surrogatePair[1]);
    result.ensureCapacity(result.capacity() + 2 + first.length() + second.length());
...
StringunicodeEscaped(char ch)
unicode Escaped
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);
...
StringunicodeEscaped(Character ch)
unicode Escaped
if (ch == null) {
    return null;
return unicodeEscaped(ch.charValue());
StringunicodeEscaped(Character ch)

Converts the string to the Unicode format '\u0020'.

This format is the Java source code format.

If null is passed in, null will be returned.

 CharUtils.unicodeEscaped(null) = null CharUtils.unicodeEscaped(' ')  = "\u0020" CharUtils.unicodeEscaped('A')  = "\u0041" 
if (ch == null) {
    return null;
return unicodeEscaped(ch.charValue());
StringunicodeEscaped(final Character ch)

Converts the string to the Unicode format '\u0020'.

This format is the Java source code format.

If null is passed in, null will be returned.

 CharUtils.unicodeEscaped(null) = null CharUtils.unicodeEscaped(' ')  = "\u0020" CharUtils.unicodeEscaped('A')  = "\u0041" 
if (ch == null) {
    return null;
return unicodeEscaped(ch.charValue());
StringunicodeEscaped(final String str)
Returns the Subl escaped string representing the input string Each character that is not 7 bit ASCII and ASCII control characters are escaped in the following form where xxxx is the hex representation of the character (it may be from 2 to 6 hex digits as needed).
String estr = escapeDoubleQuotes(str);
StringBuilder sb = new StringBuilder(str.length());
char c = 0; 
int i;
for (i = 0; i < estr.length(); i++) {
    c = estr.charAt(i);
    if (c >= 0x20 && c < 0x80) {
        if (c == '&')
...