penguina
penguina

Reputation: 185

[Java convert unicode from cmd to char]

I have the following case :

java Myprog \u03b1

And I want to read alpha value(that unicode) in a char. How could I do this in Java?

Upvotes: 0

Views: 86

Answers (1)

Davide Lorenzo MARINO
Davide Lorenzo MARINO

Reputation: 26926

You can read the string (without \u) as an integer in hexadecimal format. And convert it to char.

public class Myprog {
    public static void main(String[] args) {
        char c = (char) Integer.parseInt(args[0].substring(2), 16 ); 
        // Use char as you like
    }
}

Upvotes: 2

Related Questions