0

I want to convert String into int.

For example:

if String is "0x1F60A" then it should be convert into int same as 0x1F60A

String str = "0x1F60A";
int i = 0x1F60A; // it must be something like this.

Why I need this. Because I'm going to convert unicode int into Emoji I'm using this code.

final String emojiString = str.substring(start,end);
// value in emojiString is 0x1F60A
int unicode = // need to convert this string into int
ss.replace(start, end, new String(Character.toChars(unicode)));

Can you please let me know how can I do that.

Azeem Haider
  • 1,443
  • 4
  • 23
  • 41
  • 1
    Possible duplicate of [Convert hex string to int](https://stackoverflow.com/questions/11194513/convert-hex-string-to-int) – BakaWaii Aug 08 '17 at 04:57

2 Answers2

6

For conversion of Unicode to Int:

You have to omit the 2 first characters with .substring(2)

int code = Integer.parseInt(unicodeStr.substring(2), 16);

For conversion of String to int:

try {
    myNum = Integer.parseInt(myString);
} catch(NumberFormatException nfe) {
}
Piyush
  • 18,895
  • 5
  • 32
  • 63
komal akhani
  • 553
  • 6
  • 20
0
int unicode = Integer.parseInt(emojiString.substring(2), 16);
Marat
  • 6,142
  • 6
  • 39
  • 67