Java unicode question

It might be a stupid question, but ... Say I have a Stringlike 4e59that represents a special unicode character. How can I add \uthis symbol to the beginning so that it displays correctly? I tried the simplest solution:

String str = "4e59";
System.out.println("\\u"+str);

And a few more options, what am I missing?

+3
source share
3 answers

\ u is parsed at compile time, not runtime, so just prefixing your line with "\ u" will not work.

You can use Integer.parseInt for this parsing at runtime:

System.out.println((char)Integer.parseInt("4e59", 16));
+9
source

, , , , "\u" : "\uXXXX" javac ( , ). , "\u", .

\uXXXX , . , Java:

int i;

\u0069\u006E\u0074 \u0069\u003B
+5

You need to convert it to char:

System.out.println((char) Integer.parseInt("4e59", 16));
+4
source

Source: https://habr.com/ru/post/1720036/


All Articles