Funkydiddykong
Funkydiddykong

Reputation: 67

Print the unicode code instead of character

I would like eclipse to allow to print and save a unicode code instead of the character (For use in another program after).

String string = "\u2588";

I want the output to be \u2588 not the block character.

First time posting so sorry for anything done wrong :(.

Upvotes: 1

Views: 681

Answers (3)

Prabhunath Yadav
Prabhunath Yadav

Reputation: 185

Use this code for printing unicode char

String unicodeMessage =
        "\u7686\u3055\u3093\u3001\u3053\u3093\u306b\u3061\u306f";

        PrintStream out = new PrintStream(System.out, true, "UTF-8");
        out.println(unicodeMessage);

Upvotes: -1

Ron
Ron

Reputation: 1508

The backslash \ is an escape character, to print an actual '\' use "\\"

String s = "\\u2588"

Upvotes: 3

Simon Fischer
Simon Fischer

Reputation: 1208

String string = "\\u2588";

If you use two backslashes it does not try to detect the escape sequence.

Upvotes: 6

Related Questions