Java Utililty Methods Unicode

List of utility methods to do Unicode

Description

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

Method

Stringunicode(String ipStr)
unicode
if (ipStr == null)
    return ipStr;
switch (ipStr) {
case "\\u0001":
    return "\u0001";
case "\\u0002":
    return "\u0002";
case "\\u0003":
...
Stringunicode(String s)
unicode
final StringBuilder result = new StringBuilder();
for (char c : s.toCharArray()) {
    if (c > 127 || c == '&' || c == '|') {
        final int i = c;
        result.append("&#" + i + ";");
    } else {
        result.append(c);
return result.toString();
voidunicode(StringBuilder buf, char c)
Represent as unicode
buf.append("\\u");
int n = c;
for (int i = 0; i < 4; ++i) {
    int digit = (n & 0xf000) >> 12;
    buf.append(hex[digit]);
    n <<= 4;
StringUnicode2ASCII(String unicode)
Creates a new instance of ThaiUtil
StringBuffer ascii = new StringBuffer(unicode);
int code;
for (int i = 0; i < unicode.length(); i++) {
    code = (int) unicode.charAt(i);
    if ((0xE01 <= code) && (code <= 0xE5B)) {
        ascii.setCharAt(i, (char) (code - 0xD60));
return ascii.toString();
byte[]unicode2Byte(String s)
unicode Byte
int len = s.length();
byte abyte[] = new byte[len << 1];
int j = 0;
for (int i = 0; i < len; i++) {
    char c = s.charAt(i);
    abyte[j++] = (byte) (c & 0xff);
    abyte[j++] = (byte) (c >> 8);
return abyte;
StringUnicode2GBK(String dataStr)
Unicode GBK
int index = 0;
StringBuffer buffer = new StringBuffer();
int li_len = dataStr.length();
while (index < li_len) {
    if (index >= li_len - 1 || !"\\u".equals(dataStr.substring(index, index + 2))) {
        buffer.append(dataStr.charAt(index));
        index++;
        continue;
...
Stringunicode2native(String s)
unicodenative
if (s == null || s.length() == 0) {
    return "";
char ac[] = new char[s.length() * 2];
int i = 0;
for (int j = 0; j < s.length(); j++) {
    if (s.charAt(j) >= '\u0100') {
        char c = s.charAt(j);
...
charunicodeChar(char a, char b, char c, char d)
unicode Char
return (char) ((c2i(a) << 12) + (c2i(b) << 8) + (c2i(c) << 4) + c2i(d));
StringunicodeCodepointToString(char cp, boolean shortenIfPossible, String prefix, boolean upperCase)
Like #unicodeCodepointToString(char,boolean) if you pass in "\\u" as prefix.
if (shortenIfPossible) {
    if ((cp >= 'a' && cp <= 'z') || (cp >= 'A' && cp <= 'Z') || (cp >= '0' && cp <= '9') || cp == '\\'
            || cp == '~' || cp == '`' || cp == '.' || cp == ',' || cp == ' ' || cp == '\'' || cp == '"'
            || cp == '+' || cp == '-' || cp == '=' || cp == '_' || cp == '@' || cp == '!' || cp == '#'
            || cp == '$' || cp == '%' || cp == '^' || cp == '&' || cp == '*' || cp == ':' || cp == '['
            || cp == ']' || cp == '(' || cp == ')' || cp == '{' || cp == '}')
        return new String(new char[] { cp });
    if ('\t' == cp)
...
StringunicodeConvert(String str)
unicode Convert
char[] in = str.toCharArray();
int off = 0;
int len = str.length();
char[] out = new char[len];
int outLen = 0;
while (off < len) {
    char aChar = in[(off++)];
    if (aChar == '\\') {
...