I'm trying to convert code points, such as \u00FC
, to the character it represents.
import javax.swing.JOptionPane;
public class Test {
public static void main(String[] args) {
String in = JOptionPane.showInputDialog("Write something in here");
System.out.println("Input: " + in);
// Do something before this line
String out = in;
System.out.print("And Now: " + out);
}
}
An example to explain what I mean:
First Console line: Input: Hall\u00F6
Second Console line: And Now: Hallö
EDIT: Because sometimes it didn't work with multiple Unicodes in The Trombone Willy's answer, here is the Code fixed:
public static String unescapeUnicode(String s) {
StringBuilder r = new StringBuilder();
for (int i = 0; i < s.length(); i++) {
if (s.length() >= i + 6 && s.substring(i, i + 2).equals("\\u")) {
r.append(Character.toChars(Integer.parseInt(s.substring(i + 2, i + 6), 16)));
i += 5;
} else {
r.append(s.charAt(i));
}
}
return r.toString();
}