Java Utililty Methods Unicode Create

List of utility methods to do Unicode Create

Description

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

Method

StringtoUnicode(String original)
to Unicode
if (original == null)
    return null;
String result = "";
for (int i = 0, length = original.length(); i < length; i++) {
    if (original.charAt(i) > 0 && original.charAt(i) < 256)
        result += original.charAt(i);
    else
        result += "\\u" + Integer.toHexString(original.charAt(i)).toUpperCase();
...
StringtoUnicode(String s)
to Unicode
StringBuilder sb = new StringBuilder();
for (int i = 0; i < s.length(); ++i)
    sb.append(toUnicode(s.charAt(i)));
return sb.toString();
StringtoUnicode(String source)
to Unicode
String ret = null;
if (source == null)
    return null;
try {
    ret = new String(source.getBytes(), "8859_1");
} catch (UnsupportedEncodingException e) {
    ret = null;
return ret;
StringtoUnicode(String str)
to Unicode
try {
    return new String(str.getBytes("ISO8859_1"), "GB2312");
} catch (Exception e) {
    return str;
StringtoUnicode(String str)
to Unicode
String as[] = new String[str.length()];
String s1 = "";
for (int i = 0; i < str.length(); i++) {
    int v = str.charAt(i);
    if (v >= 19968 && v <= 171941) {
        as[i] = Integer.toHexString(str.charAt(i) & 0xffff);
        s1 = s1 + "\\u" + as[i];
    } else {
...
StringtoUnicode(String str)
to Unicode
char[] arChar = str.toCharArray();
int iValue = 0;
String uStr = "";
for (int i = 0; i < arChar.length; i++) {
    iValue = (int) str.charAt(i);
    if (iValue <= 256) {
        uStr += "\\" + Integer.toHexString(iValue);
    } else {
...
StringtoUnicode(String str)
to Unicode
String result = "";
char[] arr = str.toCharArray();
for (int i = 0; i < arr.length; i++) {
    result += toUnicode(arr[i]);
return result;
StringtoUnicode(String string)
Convert the given string to a string with unicode escape sequence for every character.
StringBuilder builder = new StringBuilder();
for (char c : string.toCharArray()) {
    builder.append(String.format("\\u%04x", (int) c));
return builder.toString();
StringtoUnicode(String strText)
to Unicode
char c;
String strRet = "";
int intAsc;
String strHex;
for (int i = 0; i < strText.length(); i++) {
    c = strText.charAt(i);
    intAsc = (int) c;
    if (intAsc > 128) {
...
StringtoUnicode(String text)
to Unicode
int bufLen = text.length() * 2;
StringBuilder sb = new StringBuilder(bufLen);
for (int i = 0; i < text.length(); i++) {
    char chr = (char) text.charAt(i);
    if ((chr > 61) && (chr < 127)) {
        if (chr == '\\') {
            sb.append('\\');
            sb.append('\\');
...