1

I am making an android app which parses XML. Since XML data contains HTML hexes (&#<dec value>), I need to convert them and then show them in my app. When I am passing 8217 to my code, it returns me some chinese/japanese (I'm not sure) character. Here is my code.

public char decToChar(String dec){
    Int decimal = Integer.parseInt(dec, 16);
    return (char)decimal;
}

I am passing value '8217' to this method and it returns chinese character instead of '.

Do anyone have any idea why its not working?

2
  • why dont you simply use the unicode character notation, something like \u8217 if I am remembering it correctly? Commented Sep 29, 2013 at 18:31
  • \u8217 gives the same.! Commented Sep 29, 2013 at 18:57

2 Answers 2

1

what are you expecting? You are probably correctly parsing the hex-value to 33303. But since you are casting it to (char) you generate a meaningless value. This is not a conversion to a character.

I would advice you to use apache commons if you can. StringEscapeUtils will do the trick.

Sign up to request clarification or add additional context in comments.

Comments

1

You can use StringEscapeUtils.unescapeHtml4 to unescape an entity:

System.out.println(StringEscapeUtils.unescapeHtml4("&#8217;"));

Should show you the expected character

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.