0

I can see emojis if I enter unicode directly and convert it to String with a method like:

int intUnicode = 0x1F601;

public String getEmojiByUnicode(int unicode) {
    return new String(Character.toChars(unicode));
}

But I just can't wrap my head around how to convert when the unicode value is a String like:

String strUnicode = "0xf601";

How to covert it to an Integer like I did it directly. When I try to use Integer.parseInt(strUnicode) compiler throws an error every time.

InputStream is = assetManager.open("emoji_unicode.txt");
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
if (is != null){
    try {
        while ((data = reader.readLine()) != null){
            sbuffer.append(data + "\n");
            String j = sbuffer.toString().trim();
            int k = Integer.parseInt(j,16);
            String l = getEmojiByUnicode(k);
            emoArray.add(l);
        }
        btn.setText(emoArray.get(5));
        is.close();
    }catch (IOException e){
        e.printStackTrace();
    }
}

It's not very hard, I know I'm very close but still it won't get to me. Any help would be very appreciated. Regard

2

1 Answer 1

0

You're attempting to parse a hex string (unicode "encodings" are hexadecimal numbers), and Integer.parseInt() has some odd limits for doing so. Take a look at this answer:

Parsing a Hexadecimal String to an Integer throws a NumberFormatException?

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

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.