0

I have a String containing ASCII representation of a character i.e.

String test = "0x07";

Is there a way I can somehow parse it to its character value.

I want something like

char c = 0x07;

But what the character exactly is, will be known only by reading the value in the string.

Haifeng Zhang
  • 30,077
  • 19
  • 81
  • 125
Nick Div
  • 5,338
  • 12
  • 65
  • 127
  • Possible duplicate of [Parsing a Hexadecimal String to an Integer throws a NumberFormatException?](http://stackoverflow.com/questions/11377944/parsing-a-hexadecimal-string-to-an-integer-throws-a-numberformatexception) – shmosel Feb 10 '17 at 20:24
  • @shmosel That answer looks good too. I just didn't find it when I was struggling with my issue because may be I wasn't searching with right keywords. – Nick Div Feb 10 '17 at 21:28

1 Answers1

2

You have to add one step:

String test = "0x07";
int decimal = Integer.decode(test);
char c = (char) decimal;
matejetz
  • 520
  • 3
  • 7