Skip to content

Latest commit

 

History

History
23 lines (19 loc) · 666 Bytes

unicode-to-string.md

File metadata and controls

23 lines (19 loc) · 666 Bytes
title description author tags
Unicode To String
Converts a unicode String into its normal representation
Mcbencrafter
string,unicode,encoding,decoding,conversion
public static String unicodeToString(String unicode) {
    StringBuilder string = new StringBuilder();
    String[] hex = unicode.split("\\\\u");

    for (int symbol = 1; symbol < hex.length; symbol++) {
        int data = Integer.parseInt(hex[symbol], 16);
        string.append((char) data);
    }

    return string.toString();
}

// Usage:
System.out.println(unicodeToString("\\u0068\\u0065\\u006c\\u006c\\u006f\\u0020\\u0077\\u006f\\u0072\\u006c\\u0064")); // "hello world"