Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAVA String to char

Tags:

java

string

char

I have a String representing the hex value of a char, such as: "0x6d4b". How can I get the character it represents as a char?

String c = "0x6d4b";
char m = ???
like image 226
user1484878 Avatar asked Jun 27 '12 07:06

user1484878


1 Answers

// Drop "0x" in order to parse
String c = "6d4b";
// Parse hexadecimal integer
int i = Integer.parseInt( c, 16 );
// Note that this method returns char[]
char[] cs = Character.toChars( i );
// Prints 测
System.out.println( cs );
like image 136
Gustav Barkefors Avatar answered Sep 19 '22 01:09

Gustav Barkefors